Author: fcspartakm
Tutorial
Tutorial is loading...
Solution (BledDest)
t = int(input())
for _ in range(t):
a, b = map(int, input().split())
if b >= a:
print(-1)
else:
print(min(b, a - b))
Author: BledDest
Tutorial
Tutorial is loading...
Solution (BledDest)
t = int(input())
for _ in range(t):
s = input()
ans = 1
if "010" in s or "101" in s:
ans += 1
if "000" in s or "111" in s:
ans += 1
print(ans)
Author: fcspartakm
Tutorial
Tutorial is loading...
Solution (BledDest)
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
p = [0 for i in range(n+1)]
for i in range(n):
p[i+1] = (p[i]+a[i]) % k
ans = 0
cnt = [0 for i in range(k)]
for i in range(k+1, n+1):
cnt[p[i-k-1]] += 1
ans += cnt[p[i]]
print(ans)
Author: BledDest
Tutorial
Tutorial is loading...
Solution (BledDest)
#include<bits/stdc++.h>
using namespace std;
void solve()
{
int n, m;
cin >> n >> m;
vector<int> d(n);
for(int i = 0; i < m; i++)
{
int x, y;
cin >> x >> y;
x--;
y--;
d[x]++;
d[y]++;
}
sort(d.begin(), d.end());
if(d[0] == 0)
cout << "Brain Melt\n";
else if(d[n - 1] == n - 1 && d[n - 2] == 1)
cout << 2 << "\n";
else
cout << "Many\n";
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
for(int i = 0; i < t; i++)
solve();
}
Author: Roms
Tutorial
Tutorial is loading...
Solution (Roms)
#include <bits/stdc++.h>
using namespace std;
int t;
int main() {
const string s25 = "2025", s26 = "2026";
cin >> t;
for (int tc = 0; tc < t; ++tc) {
int n;
string s;
cin >> n >> s;
vector <vector <int>> nxt(n, vector <int> (10));
vector <int> cur(10, n);
for (int i = n - 1; i >= 0; --i) {
cur[s[i] - '0'] = i;
for (int j = 0; j < 10; ++j)
nxt[i][j] = cur[j];
}
vector <int> d(n + 1);
vector <int> dd(n + 1);
for (int l = 0; l < n; ++l) {
int r25 = l, r26 = l;
int i25 = 0, i26 = 0;
while(i25 < s25.size() && r25 < n) {
int x = s25[i25++] - '0';
r25 = nxt[r25][x];
}
while(i26 < s26.size() && r26 < n) {
int x = s26[i26++] - '0';
r26 = nxt[r26][x];
}
int cnt = n - l;
d[l] += cnt;
--dd[l + 1];
if (r25 < r26) {
// bad == [r25..r26-1]
cnt = r26 - r25;
d[l] -= cnt;
++dd[r25 + 1];
//--dd[r26];
if(r26 < n)
--dd[r26 + 1];
}
}
vector <int> ans(n);
long long sum = 0, add = 0;
for (int i = 0; i < n; ++i) {
sum += d[i];
add += dd[i];
sum += add;
cout << sum << ' ';
}
cout << endl;
}
return 0;
}
2276F - Permutation Coloring Game
Author: BledDest
Tutorial
Tutorial is loading...
Solution (BledDest)
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9;
void upd(int& x, int y)
{
if(x > y) x = y;
}
void solve()
{
int n, k;
cin >> n >> k;
vector<int> p(n);
for(int i = 0; i < n; i++)
{
cin >> p[i];
p[i]--;
}
vector<bool> used(n);
vector<int> len;
for(int i = 0; i < n; i++)
{
if(!used[i])
{
used[i] = true;
int cur_len = 1;
int j = p[i];
while(!used[j])
{
used[j] = true;
cur_len++;
j = p[j];
}
len.push_back(cur_len);
}
}
sort(len.begin(), len.end());
reverse(len.begin(), len.end());
if(k == 1)
{
if(len[0] >= 3)
cout << "Bob\n";
else if(len[0] == 1 || n % 2 == 1)
cout << "Alice\n";
else
cout << "Bob\n";
}
else if(len[0] > k + 1)
{
cout << "Bob\n";
}
else if(len[0] == k + 1)
{
if(len.size() > 1 && len[1] == k + 1)
{
cout << "Bob\n";
}
else
{
int must_remove = 0;
int cnt1 = 0;
for(int i = 1; i < len.size(); i++)
{
if(len[i] > 1)
must_remove += len[i];
else cnt1++;
}
int alice_move = must_remove + cnt1 % (k + 1);
if(alice_move > k || alice_move == 0)
cout << "Bob\n";
else
cout << "Alice\n";
}
}
else
{
int m = len.size();
m = min(m, 2 * k);
vector<vector<vector<int>>> dp(m+1, vector<vector<int>>(k+1, vector<int>(k + 1, INF)));
dp[0][0][0] = 0;
for(int i = 0; i < m; i++)
for(int j = 0; j <= k; j++)
for(int c = 0; c <= k; c++)
{
if(dp[i][j][c] == INF) continue;
bool alice_can = (j + len[i] <= k);
bool bob_can = (i - c < k);
if(alice_can)
upd(dp[i+1][j + len[i]][c + 1], dp[i][j][c]);
upd(dp[i+1][j][c], dp[i][j][c] + (bob_can ? len[i] - 1 : 0));
}
bool alice_win = false;
for(int j = 0; j <= k; j++)
for(int c = 0; c <= k; c++)
if(dp[m][j][c] <= k)
alice_win = true;
if(alice_win)
cout << "Alice\n";
else
cout << "Bob\n";
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
for(int i = 0; i < t; i++)
solve();
}
2276G - Elimination of Players
Author: BledDest
Tutorial
Tutorial is loading...
Solution (BledDest)
#include<bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int N = 5005;
int add(int x, int y)
{
x += y;
while(x >= MOD) x -= MOD;
while(x < 0) x += MOD;
return x;
}
int mul(int x, int y)
{
return (x * 1ll * y) % MOD;
}
int sub(int x, int y)
{
return add(x, -y);
}
int binpow(int x, int y)
{
int z = 1;
while(y)
{
if(y & 1) z = mul(z, x);
x = mul(x, x);
y >>= 1;
}
return z;
}
int fact[N];
int inv[N];
void precalc()
{
fact[0] = 1;
for(int i = 1; i < N; i++)
fact[i] = mul(i, fact[i - 1]);
for(int i = 0; i < N; i++)
inv[i] = binpow(i, MOD - 2);
}
struct Blocks
{
int n;
vector<int> cutoff_pos;
vector<int> pref;
vector<int> pref_G;
vector<pair<int, int>> a;
void rebuild()
{
pref = { 0 };
pref_G = { 0 };
vector<bool> used(n);
vector<pair<int, int>> b;
cutoff_pos = vector<int>(n, -1);
int sign = 1;
int cnt = n - 1;
for(int i = 0; i < a.size(); i++)
{
int x = a[i].first;
int len = a[i].second;
if(used[x])
break;
used[x] = true;
b.push_back(make_pair(x, len));
cutoff_pos[x] = i;
int c = mul(sign, mul(len, fact[cnt]));
int c_G = mul(sign, mul(len, fact[cnt - 1]));
--cnt;
sign = sub(0, sign);
pref.push_back(add(pref.back(), c));
pref_G.push_back(add(pref_G.back(), c_G));
}
a = b;
}
int getF()
{
return pref.back();
}
int getG(int x)
{
if(cutoff_pos[x] == -1) return pref_G.back();
else return pref_G[cutoff_pos[x]];
}
void append(int x)
{
if(a.empty() || a[0].first != x)
a.insert(a.begin(), make_pair(x, 0));
a[0].second++;
rebuild();
}
Blocks(int n = 0) : n(n) {};
};
void solve()
{
int n;
cin >> n;
vector<int> a(n - 1);
for(int i = 0; i < n - 1; i++)
{
cin >> a[i];
a[i]--;
}
Blocks b(n);
vector<vector<int>> ans(n - 1, vector<int>(n));
vector<vector<int>> G(n - 1, vector<int>(n));
vector<int> F(n - 1);
for(int i = 0; i < n - 1; i++)
{
int x = a[i];
b.append(x);
F[i] = b.getF();
for(int j = 0; j < n; j++)
G[i][j] = b.getG(j);
for(int j = 0; j < n; j++)
{
if(a[i] == j) continue;
int s = add(fact[n - 1], G[i][j]);
if(i > 0)
{
s = sub(s, G[i - 1][j]);
if(a[i - 1] == j)
s = add(s, F[i - 1]);
}
ans[i][j] = s;
}
}
long long res = 0;
for(int i = 0; i < n - 1; i++)
for(int j = 0; j < n; j++)
res ^= ans[i][j] * 1ll * (i + 1) * 1ll * (j + 1);
cout << res << endl;
}
int main()
{
precalc();
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
for(int i = 0; i < t; i++)
solve();
}








Horrendously unbalanced and speedforces round, just not it man...
Thanks for your fast editorial!
contest was so unfun
My solution discussion stream for ABCDE.
It's possible to solve F in $$$O(nk)$$$.
Yet $$$O(\min(n, k)\cdot k^2)$$$ is better.
F. Case — all cycles have length k or less without dp
394617147
K is not bounded unfortunately
Unfortunately, yes(
K is cannot be more than 20
I used dfs for this part
Many people solved Problem D using DFS, even though there is an easy solution
this was worst contest for my entire lifetime, i guarantee
Yeah, you right. It is because problem c i.e. subarray could be solved by using brute force, then I think about sliding window, after I solved it by using prefix sum with frequency. For thinking process, there were many steps for solve this problem but when think that approach so that solved it easily.
F and D are cool. Thanks authors!
A somewhat dull speedforce round,while B and E are worth pondering
D is easier than C...
good!
This was one of the best rounds in a while! Thank you!
trash round
can anyone explain how the B solution is working in c++
Let $$$k$$$ be the maximum number of block after compress binary string $$$s$$$,then it can be prove that in one operation you can make $$$k\rightarrow k+2$$$ or $$$k\rightarrow k-2$$$,consider index $$$i$$$,there is two situation,$$$s_i$$$ same as adjacent character or not,
If $$$s_i$$$ same as adjacent character then if you flip $$$s_i$$$ then the block will increase $$$2$$$
If $$$s_i$$$ is not same as adjacent character there is two more specific condition,either $$$1$$$ adjacent character is not same or both,if $$$1$$$ adjacent character is not same then flip $$$s_i$$$ will not affect the result,otherwise it will decrease $$$2$$$,check the example below
Ex:
$$$1$$$ adjacent character not same
$$$[0\underline{0}]1\rightarrow 0[\underline{1}1]$$$
both adjacent character not same
$$$[0][\underline{1}][0]\rightarrow [0\underline{0}0]$$$
So you need to check does there exist $$$000$$$ or $$$111$$$ for $$$k+2$$$,and $$$010$$$ or $$$101$$$ for
Unable to parse markup [type=CF_MATHJAX]
,and $$$k$$$ is always can be obtain by doing nothing,thus answer either $$$1$$$,$$$2$$$ or $$$3$$$Consider compressing the string without changing any character, it will always be sequence of alternate 0 or 1, lets take 10101 for example, now, the comp-string will only change if we are able to remove any, one between 2 zeros (or 101) in the comp-string, to do that, in the original string, that 1 should have zeros on both sides, which is substr = "010", given in editorial. Plus there is one more case where you can increase the size of comp-string, you can think about it in the same manner.
my solution to D if any node has degree 0 answer is 0 if their is any cycle answer is MANY if the graph is a star graph answer is 2 else answer is MANY
The cycle part was not required
Hello. I don't understand how the ans is created, what is the point of dd array?
dd array is used to keep track of the arithmethic progression's difference when counting the good substring. for example, if you want to make an addition to range
[l, r], that means addingn-l, n-l-1, n-l-2, ...tol, l+1, l+2, ...respectively, each with difference of-1. the sol keeps the difference inddand tracks the total difference from0 to i (0 <= i < n)withaddwhen computing answer for each indexIn problem F, I feel that if the problem setter wanted an O(poly(k)) solution, they should have set k to 200. Otherwise, we can just DFS Alice's first move combined with an O(n) check and still get accepted, without even having to think about knapsack or any graceful DP.
Why is it named "Educational Round"? What's educational about it? Setting a problem E that easy or D brute-force cakewalk makes no sense.
F is really edu because of learning game dp.
I solved $$$E$$$ by binary search
HI heres and alternate soln to a. ik its a fairly simple one, but maybe u guys can tell me better ways to think. i cudnt quickly make out what wud a-b imply.
395201343
A question about Problem C: Why does the two-pointer technique (which somewhat resembles a sliding window of size k+1) correctly count all the answers?
Monocarp, when HL3???
Why is G rated 2100? Is it that easy?
I dont'k think so.
It's worth a higher rating!
G only 2100??? its clist rating reached to 3200......
E is really nice!! Taught me something new.
Why is G rated *2100? The more I work on it, the weirder it feels.
We can solve E in O(n), because each query can be processed in offline mode.
Why G is *2100 ??? It's quite difficult.