Идея: BledDest
Разбор
Tutorial is loading...
Решение (awoo)
for _ in range(int(input())):
s = input()
for (d, k) in zip("RGB", "rgb"):
if s.find(d) < s.find(k):
print("NO")
break
else:
print("YES")
1644B - Anti-Fibonacci Permutation
Идея: BledDest
Разбор
Tutorial is loading...
Решение (Neon)
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cout << i;
for (int j = n; j > 0; --j) if (i != j)
cout << ' ' << j;
cout << '\n';
}
}
}
1644C - Increase Subarray Sums
Идея: BledDest
Разбор
Tutorial is loading...
Решение (awoo)
INF = 10**9
for _ in range(int(input())):
n, x = map(int, input().split())
a = list(map(int, input().split()))
mx = [-INF for i in range(n + 1)]
mx[0] = 0
for l in range(n):
s = 0
for r in range(l, n):
s += a[r]
mx[r - l + 1] = max(mx[r - l + 1], s)
ans = [0 for i in range(n + 1)]
for k in range(n + 1):
bst = 0
for i in range(n + 1):
bst = max(bst, mx[i] + min(k, i) * x)
ans[k] = bst
print(" ".join([str(x) for x in ans]))
Идея: BledDest
Разбор
Tutorial is loading...
Решение 1 (awoo)
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
const int MOD = 998244353;
int main() {
int t;
scanf("%d", &t);
forn(_, t){
int n, m, k, q;
scanf("%d%d%d%d", &n, &m, &k, &q);
vector<int> xs(q), ys(q);
forn(i, q) scanf("%d%d", &xs[i], &ys[i]);
int ans = 1;
set<int> ux, uy;
for (int i = q - 1; i >= 0; --i){
bool fl = false;
if (!ux.count(xs[i])){
ux.insert(xs[i]);
fl = true;
}
if (!uy.count(ys[i])){
uy.insert(ys[i]);
fl = true;
}
if (fl){
ans = ans * 1ll * k % MOD;
}
if (int(ux.size()) == n || int(uy.size()) == m){
break;
}
}
printf("%d\n", ans);
}
return 0;
}
Решение 2 (awoo)
from sys import stdin, stdout
MOD = 998244353
ux = []
uy = []
for _ in range(int(stdin.readline())):
n, m, k, q = map(int, stdin.readline().split())
while len(ux) < n:
ux.append(False)
while len(uy) < m:
uy.append(False)
xs = [-1 for i in range(q)]
ys = [-1 for i in range(q)]
for i in range(q):
x, y = map(int, stdin.readline().split())
xs[i] = x - 1
ys[i] = y - 1
cx = 0
cy = 0
ans = 1
for i in range(q - 1, -1, -1):
fl = False
if not ux[xs[i]]:
ux[xs[i]] = True
cx += 1
fl = True
if not uy[ys[i]]:
uy[ys[i]] = True
cy += 1
fl = True
if fl:
ans = ans * k % MOD
if cx == n or cy == m:
break
for i in range(q):
ux[xs[i]] = False
uy[ys[i]] = False
stdout.write(str(ans) + "\n")
Идея: BledDest
Разбор (Перевод скоро будет)
Tutorial is loading...
Решение (awoo)
def calc(s, n):
ld = s.find('R')
res = ld * (n - 1)
y = 0
for i in range(len(s) - 1, ld - 1, -1):
if s[i] == 'D':
res += y
else:
y += 1
return res
for _ in range(int(input())):
n = int(input())
s = input()
if s.count(s[0]) == len(s):
print(n)
continue
ans = n * n
ans -= calc(s, n)
ans -= calc(''.join(['D' if c == 'R' else 'R' for c in s]), n)
print(ans)
Идея: BledDest
Разбор (Перевод скоро будет)
Tutorial is loading...