Idea: BledDest
Tutorial
Tutorial is loading...
Solution (BledDest)
t = int(input())
for i in range(t):
n = int(input())
ans = 3 * (n // 15)
n %= 15
for j in range(n + 1):
if j % 3 == j % 5:
ans += 1
print(ans)
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (Neon)
#include <bits/stdc++.h>
using namespace std;
using li = long long;
int main() {
int t;
cin >> t;
while (t--) {
li n, x, k;
cin >> n >> x >> k;
string s;
cin >> s;
for (int i = 0; i < n; ++i) {
x += (s[i] == 'L' ? -1 : +1);
--k;
if (!x) break;
}
li ans = 0;
if (!x) {
ans = 1;
for (int i = 0; i < n; ++i) {
x += (s[i] == 'L' ? -1 : +1);
if (!x) {
ans += k / (i + 1);
break;
}
}
}
cout << ans << '\n';
}
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (awoo)
for _ in range(int(input())):
n, k = map(int, input().split())
s = input()
a = list(map(int, input().split()))
l, r = 0, 10**9
res = -1
def check(d):
last = 'R'
cnt = 0
for i in range(n):
if a[i] > d:
if s[i] == 'B' and last != 'B':
cnt += 1
last = s[i]
return cnt <= k
while l <= r:
m = (l + r) // 2
if check(m):
res = m
r = m - 1
else:
l = m + 1
print(res)
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (Neon)
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int add(int x, int y) {
x += y;
if (x >= MOD) x -= MOD;
if (x < 0) x += MOD;
return x;
}
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> p(n), d(n);
vector<vector<int>> vs(n);
for (int v = 1; v < n; ++v) {
cin >> p[v];
--p[v];
d[v] = d[p[v]] + 1;
vs[d[v]].push_back(v);
}
vector<int> dp(n), tot(n);
dp[0] = tot[0] = 1;
for (int i = 1; i < n; ++i) {
for (int v : vs[i]) {
dp[v] = add(tot[d[v] - 1], d[v] == 1 ? 0 : -dp[p[v]]);
tot[d[v]] = add(tot[d[v]], dp[v]);
}
}
int ans = 0;
for (int v = 0; v < n; ++v) {
ans = add(ans, dp[v]);
}
cout << ans << '\n';
}
}
2070E - Game with Binary String
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (BledDest)
#include<bits/stdc++.h>
using namespace std;
const int N = 300003;
const int M = 3 * N;
const int S = 4 * N;
struct segtree
{
vector<int> T;
void add(int v, int l, int r, int pos, int val)
{
T[v] += val;
if(l != r - 1)
{
int m = (l + r) / 2;
if(pos < m) add(v * 2 + 1, l, m, pos, val);
else add(v * 2 + 2, m, r, pos, val);
}
}
int get(int v, int l, int r, int L, int R)
{
if(L >= R) return 0;
if(l == L && r == R) return T[v];
int m = (l + r) / 2;
return get(v * 2 + 1, l, m, L, min(m, R)) + get(v * 2 + 2, m, r, max(m, L), R);
}
int getSumLess(int l)
{
return get(0, 0, S, 0, l + M);
}
void add(int pos, int val)
{
add(0, 0, S, pos + M, val);
}
segtree()
{
T.resize(4 * S);
}
};
int threshold[] = {0, 1, 1, -2};
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
string s;
cin >> s;
vector<int> p(n + 1);
for(int i = 0; i < n; i++)
p[i + 1] = p[i] + (s[i] == '1' ? -3 : 1);
vector<segtree> trees(4);
long long ans = 0;
for(int i = 0; i <= n; i++)
{
for(int j = 0; j < 4; j++)
{
int len = (i - j + 4) % 4;
int bound = p[i] - threshold[len];
ans += trees[j].getSumLess(bound);
}
trees[i % 4].add(p[i], 1);
}
cout << ans << endl;
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (BledDest)
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<long long> cnt(1 << n);
for(int i = 0; i < m; i++)
{
string s;
cin >> s;
int mask = 0;
for(auto c : s) mask += (1 << (c - 'A'));
cnt[mask]++;
}
vector<int> a(n);
for(int i = 0; i < n; i++)
cin >> a[i];
vector<bool> odd(n);
int odd_pizzas = 0;
int odd_mask = 0;
for(int i = 0; i < n; i++)
if(a[i] % 2 == 1)
{
odd[i] = true;
odd_pizzas++;
odd_mask += (1 << i);
}
// calculating the number of bits representing odd-sized pizzas in each mask
vector<int> cnt_odd(1 << n);
for(int i = 0; i < (1 << n); i++)
for(int j = 0; j < n; j++)
if(odd[j] && ((i >> j) & 1) == 1)
cnt_odd[i]++;
// transforming the sequence a to a' (and b to b', since a and b are the same)
vector<vector<long long>> A(odd_pizzas + 1, vector<long long>(1 << n, 0ll));
for(int i = 0; i < (1 << n); i++)
A[cnt_odd[i]][i] = cnt[i];
// applying SOS DP to every row of the matrix
for(int k = 0; k <= odd_pizzas; k++)
for(int i = 0; i < n; i++)
for(int j = 0; j < (1 << n); j++)
if((j >> i) & 1)
A[k][j] += A[k][j ^ (1 << i)];
// getting the SOS DP of the matrix c' from the editorial
vector<vector<long long>> B(odd_pizzas + 1, vector<long long>(1 << n, 0ll));
for(int x = 0; x <= odd_pizzas; x++)
for(int y = 0; y <= odd_pizzas - x; y++)
for(int i = 0; i < (1 << n); i++)
B[x + y][i] += A[x][i] * A[y][i];
// applying inverse SOS DP to every row
for(int k = 0; k <= odd_pizzas; k++)
for(int i = 0; i < n; i++)
for(int j = 0; j < (1 << n); j++)
if((j >> i) & 1)
B[k][j] -= B[k][j ^ (1 << i)];
int size_ans = 0;
for(auto x : a) size_ans += x;
vector<long long> ans(size_ans + 1);
for(int i = 0; i < (1 << n); i++)
{
long long cur_cnt = B[cnt_odd[i]][i];
int sum = 0;
for(int j = 0; j < n; j++)
if((i >> j) & 1)
sum += a[j];
ans[sum] += cur_cnt;
}
for(int i = 0; i < (1 << n); i++)
{
if(i & odd_mask) continue;
int sum = 0;
for(int j = 0; j < n; j++)
if((i >> j) & 1)
sum += a[j];
ans[sum] -= cnt[i];
}
reverse(ans.begin(), ans.end());
for(auto x : ans) cout << x / 2 << " ";
cout << endl;
}








From this round I received an important tip: You don't need to read the statement incorrectly. You need to read the statement correctly.
For A: just print 3 * (n / 15) + min(3, n % 15 + 1)
Yeah
Btw in the editorial algorithm complexity is O(n), not O(1)
It's probably because before looping through n, there is
n %= 15, which ensures that n is always less than 15. Since increasing n doesn't affect the code's execution time — hence O(1).Why did my submission 308279845 for problem F result in a Denial of Judgement? The testcase information indicates "Generator is not determinate."
Damn , first time seeing this ;-; , I guess problem with codeforces, in the test case verdict it is showing Verdict: CRASHED.
I don't think question E should be in this position
Small mistake in problem A's tutorial: it should be $$$n/15$$$, not $$$n15$$$.
Forgot a \frac there, will be fixed in a few moments. Thanks for noticing!
A is just — 0 1 2 15 16 17 30 31 32 45 46 47 ....
seems like I'm the only one who printed n/15 + (n — 1)/15 + (n — 2)/15 for A lol
It seems like problem F has a problem with generator for the 64th test.
Could you check it please?
How can we calculate OR Convolution using FFT?
it's called fwt,Fast Walsh Transform
Thanks!
there is a tiny mistake in tutorial of F:
"We need to make a convolution for which some bits (represending even-sized pizzas)"
might be "representing".
not very important.
Can anyone explain me the problem D
Acknowledge that you can get to a node with depth d from all nodes that are above it with the exception of its parent node. We can calculate the number of ways to get to a specific node (lets call it dp[n] for node n), and for each node, calculate the number of ways to get to any node such that the depth is 1 less than it, then subtract the number of ways to get to the parent node. Rest of the solution is just impl and caching ways to get to all nodes of a certain depth. For a much easier variation on this problem, try a problem like https://leetcode.com/problems/climbing-stairs/ (easier) or https://www.codewars.com/kata/647d08a2c736e3777c9ae1db (a bit harder), same general idea, but with a much simpler implementation
In B problem, why are we iterating over the string only "once"?
Isn't it possible that the robot reach zero after two or more executions of the MOVES? Like when x is really far from 0, say -100 and the moves are like "RRL".
"If the robot has completed all commands and is not at 0, it stops."
Any better intuitive approach for E?
I can't seem to see any possibility that I would build a solution as given in the editorial during a timed contest.
for E (c0>=3*c1+2 or c0==3*c1-1) is enough for player 1 to win otherwise player 2 wins
can u explain your reasoning in brief?
I don't get the solution for C at all. It seems like it completely ignores the possibility that we might want to color some red blocks to minimize the penalty even though first test example in the problem statement does so... Test:
6 1
BRRRRB
100 1 1 1 1 100
As far as I can tell, the best operation for this test is to paint the entire strip blue so we cover both 100 and the penalty is 4. If I feed this test into solution code above, output is 1. And it still gets accepted. How?
Thats coz they've told that the final penalty is the max of all the penalties of the wrong colored cell,.... Not the sum :-)
Guys how like how tf you guys manage to even understand the 4th test case in problem C?...Yeah I know BS is to be applied since min-max is been asked but again how tf ?