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;
}
nice editorial
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, no need for the O(n) complexity shown in the solution.
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 ....
i do not got the logic for B in 1 hr.
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?
in E, if the condition for player 2 was to choose at least one 0 instead of 1, how would the solution have changed?