Thank you for participating in the contest! I hope you enjoyed all problems :) Also, thanks to reirugan for proofreading the editorial.
| Predictor | A | B | C1 C2 | D | E | F | G |
|---|---|---|---|---|---|---|---|
| yse | 800 | 800 | (900 — 1000) | 1200 | 1400 | 1700 | 2000 |
| Wageeh | — | 1000 | (1300 — 1300) | 1500 | — | — | 1900 |
| Proof_by_QED | 800 | 800 | (1000 — 1100) | 1300 | 1300 | 1900 | 2100 |
| detective...dots | 800 | 900 | (1100 — 1100) | 1300 | 1400 | 1800 | 2100 |
| Mr_Bald | 800 | 900 | (1100 — 1200) | 1400 | 1500 | 1800 | — |
| Argentum47 | 800 | 900 | (1000 — 1200) | 1300 | 1400 | 1800 | 2000 |
A — Riptide
Assume $$$a \le b \le c$$$, does $$$b$$$ ever change?
For simplicity, let's assume $$$a \le b \le c$$$ (we can sort the input to achieve this). The operation decreases $$$c$$$ by $$$1$$$ and increases $$$a$$$ by $$$1$$$. Therefore, $$$a$$$ is getting closer to $$$b$$$ and $$$c$$$ is also getting closer to $$$b$$$. The round ends when $$$2$$$ players have the same value, so the answer is $$$\min(b - a, c - b)$$$ since if either $$$a$$$ or $$$c$$$ become equal to $$$b$$$, the game will end.
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while(t--) {
vector<int> v(3);
for(int &x : v) cin >> x;
sort(v.begin(), v.end());
cout << min(v[2] - v[1], v[1] - v[0]) << endl;
}
}
B — Evanescent
If we perform the operation on any character in a maximal contiguous block of length $$$ \gt 1$$$, then $$$f(s') = f(s)$$$.
The function $$$f(s)$$$ converts every maximal contiguous block into a block of size $$$1$$$. Therefore, removing a character from a block does not change anything if the block will still exist. The only way we can delete the whole block is if it had a size of $$$1$$$. This allows to delete the sole character that exists in the block, additionally achieving $$$f(s') \lt f(s)$$$.
When deleting a block of size $$$1$$$, we should consider what happens when the left block touches the right block. If they both contain the same character, then they would merge into one block. Therefore, the answer would decrease by $$$2$$$ (our $$$1$$$-sized block got removed, and $$$2$$$ separate blocks got merged into one).
Otherwise, if the blocks do not contain the same character, then the answer would decrease by $$$1$$$ since nothing will happen other than removing the $$$1$$$-sized block.
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while(t--) {
int n;
cin >> n;
string s;
cin >> s;
int ans = 1, x = 0;
for(int i = 1; i < n; i++) {
if(s[i] != s[i - 1]) ans++;
if(i == n - 1) break;
if(s[i] != s[i - 1] && s[i] != s[i + 1]) {
if(s[i + 1] == s[i - 1]) x = 2;
else x = max(x, 1);
}
}
cout << ans - x << endl;
}
}
C1 — Marenol (easy version)
The operation is equivalent to freely swapping $$$a_i$$$ with $$$a_{i+2}$$$ for any valid index $$$i$$$.
After the reduction from Hint 1, we can treat $$$a$$$ as two separate strings.
Notice that the operation can be treated as swapping $$$a_i$$$ with $$$a_{i+2}$$$, this works since the operation does not change the middle element, and only changes the first one and the third one.
Because an element can only move in steps of two, it can never change the parity of its index. Any character at an odd position will always remain at an odd position, and the same applies for even indices.
Since we have the power to swap the characters at odd indices endlessly (as many times as we want), we can rearrange them into any arrangement we want, independently of the characters at even indices. Therefore, the elements at odd positions in $$$a$$$ can match the elements at odd positions in $$$b$$$ if they have the same number of ones (or zeros). The same can be applied for even positions.
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while(t--) {
int n;
cin >> n;
string a, b;
cin >> a >> b;
int cnta[2] = {}, cntb[2] = {};
for(int i = 0; i < n; i++) {
cnta[i % 2] += a[i] == '1';
cntb[i % 2] += b[i] == '1';
}
cout << (cnta[0] == cntb[0] && cnta[1] == cntb[1] ? "YES" : "NO") << endl;
}
}
C2 — Marenol (hard version)
Building off the core observation from the easy version, we know that elements are strictly trapped in their own parity. Odd-indexed characters only interact with odd-indexed characters, and even with even.
The problem then boils down to a classic task: what is the minimum number of adjacent swaps needed to transform a binary array into another?
Since all '$$$\texttt{1}$$$'s are identical, they never need to leapfrog over each other. The optimal path is always for the $$$k$$$-th '$$$\texttt{1}$$$' in your starting array to walk directly to the position of the $$$k$$$-th '$$$\texttt{1}$$$' in your target array.
To implement this, just iterate through both strings and collect the positions of the '$$$\texttt{1}$$$'s in the odd indices into one list, and the positions of the '$$$\texttt{1}$$$'s in the even indices into another. If the lengths of the corresponding lists for $$$a$$$ and $$$b$$$ don't match, it's impossible to transform, so output $$$-1$$$. Otherwise, just sum up the absolute differences between the $$$k$$$-th elements of the starting and target lists for both the odd and even arrays. That sum, divided by $$$2$$$, is your exact minimum number of operations. We divide by $$$2$$$ because one operation moves characters by $$$2$$$ steps.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
int t;
cin >> t;
while(t--) {
int n;
cin >> n;
string a, b;
cin >> a >> b;
ll ans = 0;
bool ok = true;
for(int k = 0; k < 2; k++) {
vector<int> p1, p2;
for(int i = k; i < n; i += 2) {
if(a[i] == '1') p1.push_back(i);
if(b[i] == '1') p2.push_back(i);
}
if(p1.size() != p2.size()) {
ok = false;
break;
}
for(int i = 0; i < p1.size(); i++) ans += abs(p1[i] - p2[i]);
}
if(!ok) cout << -1 << endl;
else cout << ans / 2 << endl;
}
}
D — Silhouette
Equal values in $$$a$$$ will always have the exact same shadow, and larger elements always have strictly larger shadows. So if you sort the distinct values of $$$b$$$, they correspond in order to the distinct values of $$$a$$$: the group with the $$$i$$$-th smallest value has shadow equal to the $$$i$$$-th smallest distinct value in $$$b$$$.
Let $$$s_1 \lt s_2 \lt \dots \lt s_m$$$ be the distinct sorted values of $$$b$$$, and let group $$$i$$$ be all elements sharing the value corresponding to $$$s_i$$$. Then $$$s_i$$$ is the sum of all groups smaller than group $$$i$$$, and $$$s_{i+1}$$$ is that same sum plus group $$$i$$$ itself. So $$$s_{i+1} - s_i = c_i \cdot v_i$$$, where $$$c_i$$$ is the count of elements in group $$$i$$$ and $$$v_i$$$ is their value.
What must $$$s_1$$$ be? And once every $$$v_i$$$ is pinned down by the equation above, is there a group left with no equation constraining its value? What's the smallest legal choice for it?
It's easy to see that equal values in $$$a$$$ produce equal shadows. The converse also holds: distinct values in $$$a$$$ always produce distinct shadows, and moreover a larger value always produces a larger shadow. So if we sort the distinct values of $$$a$$$ as $$$v_1 \lt v_2 \lt \dots \lt v_k$$$ with frequencies $$$c_1, \dots, c_k$$$, then the shadow of group $$$i$$$ is simply the sum of all smaller groups, $$$S_{i-1} = \sum_{j \lt i} c_j v_j$$$, and these prefix sums satisfy $$$S_0 = 0 \lt S_1 \lt \dots \lt S_{k-1}$$$. In other words, the distinct values of $$$b$$$, sorted, correspond exactly and in order to these prefix sums.
This gives a direct reconstruction. Sort the distinct values of $$$b$$$ as $$$s_1 \lt s_2 \lt \dots \lt s_m$$$; since $$$S_0$$$ must be $$$0$$$, we need $$$s_1 = 0$$$, otherwise the answer is $$$-1$$$. The count of $$$s_i$$$ in $$$b$$$ gives $$$c_i$$$, the size of group $$$i$$$, and since $$$s_{i+1} - s_i = c_i \cdot v_i$$$, we can recover $$$v_i = \frac{(s_{i+1} - s_i)}{c_i}$$$. If this division isn't exact, or if the resulting $$$v_i$$$ doesn't exceed $$$v_{i-1}$$$, no valid array exists. The very last group has no such equation to pin it down, so to keep $$$a$$$ lexicographically smallest we assign it the smallest legal value, one more than the previous group's value.
Once every group's value is known, replace each $$$b_i$$$ by its group's value to get $$$a$$$.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
int t;
cin >> t;
while(t--) {
int n;
cin >> n;
vector<ll> b(n);
map<ll, ll> freq;
for(int i = 0; i < n; i++) {
cin >> b[i];
freq[b[i]]++;
}
if (!freq.count(0)) {
cout << -1 << endl;
continue;
}
map<ll, ll> ans;
ll prv_shadow = 0, prv_cnt = 0, lst = 0;
bool ok = true;
for(auto [cur_shadow, cur_cnt] : freq) {
if(cur_shadow != 0) {
ll diff = cur_shadow - prv_shadow;
if(diff % prv_cnt != 0) {
ok = false;
break;
}
ll u = diff / prv_cnt;
if(u <= lst) {
ok = false;
break;
}
ans[prv_shadow] = u;
lst = u;
}
prv_shadow = cur_shadow;
prv_cnt = cur_cnt;
}
if(!ok) {
cout << -1 << endl;
continue;
}
ans[prv_shadow] = lst + 1;
for(int i = 0; i < n; ++i) cout << ans[b[i]] << " \n"[i == n - 1];
}
}
E — Chronostasis
The problem states that $$$b_i = a_i - a_{i-1}$$$. This directly implies that $$$a_i = a_{i-1} + b_i$$$. If you assume $$$a_0 = 0$$$, you can view $$$a$$$ simply as the prefix sums of some permutation of $$$b$$$.
The standard way to achieve a lexicographically smallest sequence is to build it greedily from left to right, making $$$a_1$$$ as small as possible, then $$$a_2$$$ as small as possible, and so forth.
Since $$$a_{i-1}$$$ is fixed from the previous steps, minimizing $$$a_i$$$ means you must pick the smallest available $$$b_i$$$. However, the problem imposes a strict rule: every element in $$$a$$$ must be strictly positive ($$$a_i \ge 1$$$). How does this restrict your choice of $$$b_i$$$?
Let's rewrite the given operation backwards. We are told that $$$b_i = a_i - a_{i-1}$$$. By rearranging this, we get $$$a_i = a_{i-1} + b_i$$$. If we define $$$a_0 = 0$$$, the array $$$a$$$ is essentially just the prefix sums of some permutation of the array $$$b$$$.
We are asked to find a permutation of $$$b$$$ that produces an array $$$a$$$ satisfying two conditions: every $$$a_i$$$ must be strictly positive, and $$$a$$$ must be lexicographically smallest.
To construct the lexicographically smallest array $$$a$$$, we should build it greedily from left to right. Suppose we have already successfully constructed the prefix of $$$a$$$ up to $$$a_{i-1}$$$. To determine $$$a_i$$$, we need to choose an unused element from $$$b$$$ to act as $$$b_i$$$. Since $$$a_{i-1}$$$ is already fixed, minimizing $$$a_i$$$ is exactly the same as picking the smallest possible $$$b_i$$$.
However, we can't just pick the absolute minimum available element because we must guarantee that $$$a_i \ge 1$$$. Substituting our earlier equation, this means $$$a_{i-1} + b_i \ge 1$$$, which simplifies to $$$b_i \ge 1 - a_{i-1}$$$.
This gives us a clear greedy strategy. At each step $$$i$$$, we must select the smallest available element in $$$b$$$ that is greater than or equal to $$$1 - a_{i-1}$$$. To implement this efficiently, we can insert all elements of the given array $$$b$$$ into a multiset. We maintain a running sum variable to represent $$$a_{i-1}$$$ (initially $$$0$$$). At each step, we query the multiset for the lower_bound of $$$1 - a_{i-1}$$$. If the iterator returns the end of the multiset, it means no available element is large enough to keep the current value strictly positive. In this case, a valid array cannot be formed, and we immediately output $$$-1$$$. If a valid element is found, we add it to our running sum to compute $$$a_i$$$, store it in our answer array, and erase that element from the multiset. We repeat this process $$$n$$$ times.
#include <bits/stdc++.h>
#define int long long
using namespace std;
void solve() {
int n, cur = 0;
cin >> n;
multiset<int> b;
for(int i = 0; i < n; i++) {
int x;
cin >> x;
b.insert(x);
}
vector<int> ans(n);
for(int i = 0; i < n; i++){
auto it = b.lower_bound(1 - cur);
if(it == b.end()) return void(cout << -1 << '\n');
cur += *it;
b.erase(it);
ans[i] = cur;
}
for(int i = 0; i < n; i++) cout << ans[i] << " \n"[i == n - 1];
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while(t--) solve();
}
F — Whiplash
Try tracing the array elements after performing two consecutive operations, say on index $$$i$$$ and then on index $$$j$$$. If you look at the set of resulting values and ignore their order, how does it compare to the set of values you would get if you only performed a single operation on index $$$j$$$?
Any sequence of operations results in an array that is just a permutation of either the original array $$$a$$$, or the array $$$a$$$ after exactly one operation.
Let's analyze how a single operation affects the overall XOR sum of the array. Let $$$S_a$$$ be the XOR sum of all elements in $$$a$$$. When we choose an index $$$i$$$, we XOR $$$n-1$$$ elements with $$$a_i$$$. Since $$$n$$$ is even, $$$n-1$$$ is odd. The new XOR sum of the array will be $$$S_a \oplus (a_i \text{ XORed } n-1 \text{ times})$$$, which simplifies perfectly to $$$S_a \oplus a_i$$$.
Now, let's observe what happens if we perform multiple operations. Suppose we perform an operation on index $$$i$$$, followed by an operation on index $$$j$$$. After the first operation, the element at index $$$j$$$ becomes $$$a_j \oplus a_i$$$, and the element at index $$$i$$$ remains $$$a_i$$$. All other elements $$$a_k$$$ become $$$a_k \oplus a_i$$$.
During the second operation, we XOR everything (except index $$$j$$$) with the current value at index $$$j$$$, which is $$$a_j \oplus a_i$$$.
Let's look at the resulting values:
- For any other index $$$k$$$, the value becomes $$$(a_k \oplus a_i) \oplus (a_j \oplus a_i) = a_k \oplus a_j$$$.
- For index $$$i$$$, the value becomes $$$a_i \oplus (a_j \oplus a_i) = a_j$$$.
- For index $$$j$$$, the value remains $$$a_j \oplus a_i$$$.
If we look at this final set of values, it is exactly the same as if we had skipped the first operation and only performed a single operation on index $$$j$$$ from the very beginning. The order of the elements is different, but the set of values is identical.
This reveals the core property of the problem: no matter how many operations you perform, the resulting array (ignoring the order of elements) will either be identical to the original array $$$a$$$, or identical to the array $$$a$$$ after exactly one operation.
This gives us a straightforward solution. First, sort both arrays. If $$$a$$$ and $$$b$$$ are already identical, we output "YES" (0 operations needed). If they are not identical, we need to simulate exactly one operation. Which element $$$a_i$$$ should we use? We know from our first observation that the target XOR sum $$$S_b$$$ must equal $$$S_a \oplus a_i$$$. By rearranging this, the required element must be $$$a_i = S_a \oplus S_b$$$. We compute this target value $$$x = S_a \oplus S_b$$$. If $$$x$$$ does not exist in our initial array $$$a$$$, we can immediately output "NO". If it does exist, we find its index, apply the operation to array $$$a$$$, sort the modified array, and check if it now matches $$$b$$$.
#include <bits/stdc++.h>
using namespace std;
signed main() {
int t;
cin >> t;
while(t--) {
int n;
cin >> n;
vector<int> a(n), b(n);
for(auto &it : a) cin >> it;
for(auto &it : b) cin >> it;
sort(a.begin(), a.end());
sort(b.begin(), b.end());
if(a == b) {
cout << "YES" << endl;
continue;
}
int x = 0;
for(auto it : a) x ^= it;
for(auto it : b) x ^= it;
int idx = -1;
for(int i = 0; i < n; i++) {
if(a[i] == x) {
idx = i;
break;
}
}
if(idx == -1) {
cout << "NO" << endl;
continue;
}
for(int i = 0; i < n; i++) {
if(i == idx) continue;
a[i] ^= x;
}
sort(a.begin(), a.end());
cout << (a == b ? "YES" : "NO") << endl;
}
}
G — Nightcrawler
Because no subset can contain branching paths, two distinct leaves can never belong to the same subset. If the tree has $$$\ell$$$ leaves, you need at least $$$\ell$$$ subsets. Any $$$k \lt \ell$$$ is impossible. For $$$k \ge \ell$$$, the condition is always satisfiable since you can always break paths into smaller singletons.
Try to build the solution bottom-up. Each leaf starts a path. When these paths meet at a parent node, the parent can only join one of them. To maximize the total score, which path's maximum should the parent node interact with?
It is always optimal for the parent to join the path that currently has the smallest maximum. If the parent's value is larger, it successfully increases that path's maximum, leaving the old maximum behind as a spare value. If the parent is smaller, the path is unaffected, and the parent itself becomes the spare value that we can use if we are allowed extra subsets.
The core restriction is that every subset must form a straight vertical chain (an ancestor-descendant path). This immediately tells us that two distinct leaves can never be placed in the same subset. Consequently, the minimum number of subsets $$$k$$$ we can ever form is exactly the number of leaves in the tree, which we will call $$$\ell$$$. For any $$$k \lt \ell$$$, a valid partition is impossible, and we output $$$-1$$$. For $$$k \ge \ell$$$, it is always possible because we can just break valid chains into individual singleton nodes.
Let's build the optimal chains from the bottom up. Every leaf initially forms its own chain where the maximum value is just the leaf's value. As we move up the tree, paths merge at a parent node $$$u$$$. The node $$$u$$$ must join exactly one of the chains coming from its descendants.
To maximize the overall sum of chain maximums, $$$u$$$ should greedily join the chain with the lowest current maximum. Let's say the smallest maximum among all incoming chains is $$$x$$$. If $$$a_u$$$ is greater than $$$x$$$, placing $$$u$$$ in this chain upgrades its maximum from $$$x$$$ to $$$a_u$$$. The old maximum $$$x$$$ doesn't disappear; it gets detached and becomes an extra node that we can use to form a new chain if we are allowed to use more than $$$\ell$$$ subsets. Conversely, if $$$a_u \le x$$$, placing $$$u$$$ in the chain doesn't improve the maximum at all, so $$$a_u$$$ itself becomes the detached spare node.
This process translates elegantly into a data structure approach. For each subtree, we can maintain the maximums of its active chains using a min-heap (a priority queue). When we process a node $$$u$$$, we merge all the heaps of its children. To do this efficiently, we always merge smaller heaps into larger heaps, a technique known as small-to-large merging. Once the children's paths are merged, we extract the absolute minimum element from $$$u$$$'s heap, compare it with $$$a_u$$$, push the larger of the two back into the active heap, and append the smaller one to a global list of extra available values.
By the time we finish processing the root, the root's heap will contain exactly $$$\ell$$$ elements, representing the maximums of the $$$\ell$$$ essential chains. The sum of these elements gives our optimal answer for exactly $$$\ell$$$ subsets. To find the answer for larger values of $$$k$$$, we simply sort our global list of extra values in descending order and greedily add the largest available extra to our running total for each additional subset allowed.
Because of the small-to-large merging, each element is moved between heaps at most $$$\mathcal{O}(\log n)$$$ times. Each heap operation takes logarithmic time, resulting in an overall time complexity of $$$\mathcal{O}(n \log^2 n)$$$, which comfortably passes the time limits.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve() {
int n;
cin >> n;
vector<ll> a(n + 1);
for(int i = 1; i <= n; i++) cin >> a[i];
vector<int> p(n + 1);
for(int i = 2; i <= n; i++) cin >> p[i];
vector<priority_queue<ll, vector<ll>, greater<ll>>> pq(n + 1);
vector<ll> av;
for(int i = n; i >= 1; i--) {
if(pq[i].empty()) pq[i].push(a[i]);
else {
ll x = pq[i].top();
pq[i].pop();
pq[i].push(max(x, a[i]));
av.push_back(min(x, a[i]));
}
if(i > 1) {
int par = p[i];
if(pq[par].size() < pq[i].size()) swap(pq[par], pq[i]);
while(!pq[i].empty()) {
pq[par].push(pq[i].top());
pq[i].pop();
}
}
}
int l = pq[1].size();
ll sum = 0;
while(!pq[1].empty()) {
sum += pq[1].top();
pq[1].pop();
}
vector<ll> ans(n + 1, -1);
ans[l] = sum;
sort(av.rbegin(), av.rend());
for(int i = 0; i < av.size(); i++) {
sum += av[i];
ans[l + i + 1] = sum;
}
for(int k = 1; k <= n; k++) cout << ans[k] << " \n"[k == n];
}
int main() {
int t;
cin >> t;
while(t--) solve();
}









Guys is there an alternative sol for D
basically what the editorial means is they take the sum of one particullar number divided by the amount of number smaller than it, if its not divisible then its impossible to create an array, if not they they need to replace the smaller number to the larger number divided by the amount of smaller one, reminder that it has to be larger than the previous replaced number
My solution: 387315277
Nice, thank you
Excellent contest.
yse's rounds are the greatest
BROOO! I COULD HAVE SOLVED G, I spent too much time on D T-T :(((((((((
That's so unlucky bro, I only participated for about 15 minutes then I went to sleep
Amazing contest, problems were too good, in my opinion B was harder than C1 and C2
Yeahh ! felt the same
Yeah me too
figuring out the solutions is easier than implementing the solutions lol
also c2 isnt harder than c1 at all, this was still a fun contest though
How is C2 not harder than C1?
Well i mean c2 is definitely harder than c1, but it isnt that much harder, figuring out the c2 optimal path isnt that hard compared to figuring out c1 solution, im sorry if i sounded rude
I agree
I mean to be able to solve C2 you need to be able to solve C1, so they are at least on the same level of difficulty. But i will agree that C2 wasnt much harder than C1 at all.
once C1's logic is found, C2 felt obvious ^_^
I don't think I implemented small-to-large properly for one of my AC solutions to G, can someone hack?
https://codeforces.me/contest/2254/submission/385638977upd: wrong link, sorry. https://codeforces.me/contest/2254/submission/385633001
upd2: hacked, thanks.
I will attempt
im sorry to keep asking, but can you see why my G got WA?
i basically did what was told in the editorial and yet i got it wrong :/
https://codeforces.me/contest/2254/submission/385673245
1 4 2 2 1 1 1 2 2
DFS returned only one value, prematurely "closing off" the other chains. The fundamental reason is that the question only requires that there be an ancestral relationship between the points, without demanding that the set forms a continuous path.
btw, G also has a brainless-but-implementation-hell randomised solution that runs in $$$O(n \log^2{n})$$$ (feel free to hack): 385660205
Some sweaty tryhard seems to have hacked the constant factor
Your code is O(n^2)
One of us is being stupid here and your rating unfortunately suggests that it's me.
Could you describe your adversarial test case? From my analysis, the expected runtime seems to be the same as the editorial's solution.
Each blue node is expected to jump n/2 times
ok yeah I was being retarded
gpt found a counter-example too: https://chatgpt.com/share/6a73d92c-9d70-83ee-a28f-97189651dca1
one of the bes Tutorials that i seen in CF
thnaks for the Good Contest
Can someone please explain me why my G got WA?
385673245
honestly, the perfectly balanced contest i have given so far, thank you yse
I want to hack
Why is the hack opening so slowly?
G is nice, thanks!
good contest, yse thank you
In B I thought f was only treating subsequences of maximum length. Very unfortunate that there was no example to point the other way.
EVen after getting E, it got me in lot of Confusion!
UPD : more fkd up by the fact, this code got me wrong ans on C2 :(
inspite the idea and implementation being on the right track
https://codeforces.me/contest/2254/submission/385672566
UPD : the mistake in C2 was "no\n" in impossible cases — instead of '-1'
it is like this since i pasted C1 code directly, wtf!
that's unfortunate, i made the same mistake lol, but luckily i figured out the interger overflow
Yeah, I had a similar issue.. Got 4 wrong submission due same mistake.
great contest learned a lot :0 thanks ;)
you guys are soo cool i just can't help choking on easy questions, even today i just couldnt bring myself to think away from dp for C1 and C2 :(
C2 was way too DP! I could not submit it during the contest as I thought the criteria for figuring out the minimum amount of moves was actually a dp.
It was a nice contest, and it shows you can't just stick with the first idea that comes into your mind, lmao
Same, tried dp, even after optimizing it, it didnt work.
D was hard but nice !!
I'm a bit confused about B.
I cannot understand, why removing single character can influence only 1-char sequence and merges. But what about changing the maximum length of the sequence ? For example, consider s = 'aaabbcc'. If we remove 'a' the f(s') will be == 3, or not ? Cause the string s' will reduce to 'abc', now we have maximum blocks length == 2, not 3, so 3 substrings will be reduced, not one ? But it is not covered in Solution.
What I've missed ?
I think you are complicating the problem. It has got nothing to do with substring. It just asks if we can reduce the length or not. See if we have a single character somewhere ini between then its bound to be removed. The interesting part is that what that single character should be.
Example: Consider string s = 'aabcbbcd' If here I remove b then I get final string as acbcd. But if I remove c then I get abcd which is smaller. So technically we should try to remove a character that has same character blocks on either sides.
Why after removing c from s = 'aabcbbcd' we get 'abcd'? If we remove c that is between b characters according to the problem statement, as I have understood it, we should get 'aabcd', because we shrink only the blocks of maximum length (3 in this case) ? "Every maximal contiguous block of identical characters". What is the point of the "maximal" word here ?
You have to combine the first a with the second as well. Because its the same block.
Once again — "Every maximal contiguous block of identical characters". What is the point of the "maximal" word here ? If it were written "Every contiguous block of identical characters" — then ok, we will replace "aa" with "a", but if we consider only "maximal" block of identical characters, then we should consider only "bbb". And if it was supposed, that we consider maximal block for each different characters, in this case we also can find examples, when removing 1 character from maximal block will produce two or more maximal blocks instead of one. For example, "aabbaaccaaa" — we should reduce only "aaa" to "a". But if we remove last "a" we should reduce all 3 "aa" blocks to "a".
I think its maximal word is making you confused. The problem statement is pretty straightforward to understand.
You are confusing maximal and maximum. A maximal collection is one that you cannot add to without violating its property.
So, for a contiguous block of identical characters, it is maximal if there isn't a position next to it that is the same character. Otherwise, you could extend it and it would remain valid.
Claim: You either can reduce the number of blocks in 0, 1 or 2. Think which are the ways!
My solution for Problem B. But it fails on test case 2. What could be wrong here. TLDR; If we have a character block of length 1 then we can remove it. If it has same character on either sides than those sides will merge so we will decrease answer by 2. Else only by 1. Please help me out with this people. Thank you!
Code:
D felt harder than E, especially implementation wise
This submission is stuck in the queue and shows
Running on test 3while being actually tested with wa on test 2. yse这个D纯码量题放这个位置好吗
to be honest, E is easier than D, xswl
This was a very nice contest, I liked C1 and D. Good job yse :D
I didn't get any idea on how to think on C1 just give some way or things because i don't want help from any LLM or editorial
Just observe even and odd indices of a and b. The solution will be obvious there after
thnks bruh :D
observe that the first and last character of each operation is just 0 and 1 while the middle character can be anything. This motivates me to think about the index's parity of each element
Great insight thnx bro :D
Hii guys, Can you please check my soln. to C2? It gave "Wrong Answer" on Test Case 8. I can't figure out why?
Here's the link: https://codeforces.me/contest/2254/submission/385659954
int overflow.. Try using long long
I seriously can't believe why such a basic thing did not come into my mind at the time of contest.
Happens to best of uss T_T T_T
i also got the same error , but was able to figure out issue
я новичек, я поучавствовал и сделал некоторые задачи и у меня есть вопрос, когда появится или где можно увидеть свой рейтинг? Заранее спасибо
even i found d much harder than e
true. D really needs more thought than E
In E why my solution couldn't get AC? My Code I tried 9 submissions but couldn't get the AC :(
before using
zero, you should usenegas much as possibleThanks bro i will submit my code tomorrow after system testing.
Bro you were right now i got the AC thanks i wish i could solve it during contest
very wonderful constructive!!!
Nice contest ,S0lved till C2 , will try rest of the questions before the contest.
infact c1 was easier than b, wasted a lot of time on b...
Is F still solvable if n could be odd? I didn't notice that n is guaranteed to be even during contest and struggled a lot..
I wondered the same. In short, no, or at least not that I'm aware of. As for why:
Firstly, notice that through a series of operations, we can permute $$$a$$$ however we'd like. Furthermore, we have the option to make $$$a$$$ of the form $$$[a_1, a_2 \oplus a_1, a_3 \oplus a_1, \ldots, a_n \oplus a_1]$$$ via a final operation.
Thus, the problem becomes: "Can we permute $$$a$$$ such that $$$a_1 = b_1$$$ and $$$a_i = b_i \oplus a_1$$$ for $$$i \gt 1$$$?"
Now define $$$X(a) = \bigoplus\limits_{i = 1}^{n}{a_i}$$$. Separating out the first element gives
$$$X(a) = a_1 \oplus \bigoplus\limits_{i = 2}^{n}{a_i}$$$.
Since $$$a_i = b_i \oplus a_1$$$ for $$$i \gt 1$$$, substitute this into the expression:
$$$X(a) = a_1 \oplus \bigoplus\limits_{i = 2}^{n}{(b_i \oplus a_1)}$$$.
Now split the XOR:
$$$X(a) = a_1 \oplus \bigoplus\limits_{i = 2}^{n}{b_i} \oplus \bigoplus\limits_{i = 2}^{n}{a_1}$$$.
Since the interval $$$[2,n]$$$ contains an odd number of elements when $$$n$$$ is even, it follows that
$$$\bigoplus\limits_{i = 2}^{n}{a_1} = a_1$$$.
So the expression becomes
$$$X(a) = a_1 \oplus \bigoplus\limits_{i = 2}^{n}{b_i} \oplus a_1$$$.
The two copies of $$$a_1$$$ cancel, leaving
$$$X(a) = \bigoplus\limits_{i = 2}^{n}{b_i}$$$.
Finally, since
$$$X(b) = b_1 \oplus \bigoplus\limits_{i = 2}^{n}{b_i}$$$,
we can rewrite the above as
$$$X(a) = X(b) \oplus b_1$$$.
Recalling that $$$a_1 = b_1$$$, we conclude
$$$a_1 = X(a) \oplus X(b)$$$.
Hopefully that wasn't too confusing, but the key point is that $$$\bigoplus\limits_{i = 2}^{n}{a_1} = a_1$$$ when $$$n$$$ is even because there are an odd number of copies of $$$a_1$$$. For odd $$$n$$$, there are an even number of copies instead, so $$$\bigoplus\limits_{i = 2}^{n}{a_1} = 0$$$, and the final conclusion is only $$$X(a) = X(b)$$$, which doesn't determine $$$a_1$$$.
Thanks for your reply! I tried to consider possible $$$a_1$$$ bit by bit: for one bit, if $$$a_1$$$ is not set, then it has no influence at all; otherwise, let the number of $$$a_i$$$ which is not set on this bit be $$$c_0$$$, set be $$$c_1$$$(including $$$a_1$$$ itself). After the operation, let the new numbers for $$$b$$$ be $$$c_0'$$$ and $$$c_1'$$$, then
$$$c_0'=c_1-1$$$ and $$$c_1'=c_0+1$$$.
Since $$$c_0+c_1=n$$$, we would know that
$$$c_1+c_1'=n+1$$$.
So for each bit, we just compute $$$c_1$$$ for a and $$$c_1'$$$ for b, if $$$c_1+c_1'=n+1$$$, then $$$a_1$$$ is set; if $$$c_1=c_1'$$$, then $$$a_1$$$ is not set. For even n this is trivial, since if $$$c_1+c_1'=n+1$$$, $$$c_1$$$ and $$$c_1'$$$ must differ; but for odd n, we may have $$$c_1=c_1'=(n+1)/2$$$, in which case we cannot determine whether $$$a_1$$$ is set on this bit. So maybe there are still many candidates after considering every bit.
UPDATE: this got hacked, 385697542, it is possible to construct a test case where the probability significantly skews from 50%.
If n is odd we would need another approach, (i got this from Gemini):
since we need an element from a and perform the operation on it, we can brute force this element. for checking we use randomization, we pick 30 random elements from the array b, and use those as our sample for testing.
lets say the current element a[i] is x, so for x to be valid, for every element y from out sample, y ⊕ x should be in a.
picking 30 elements is sufficient because suppose we lucked out for every of those 30 numbers, the probability of such event is very small; (0.5) ^ 30.
finally we check if this current element x, makes the multisets of the two arrays equal.
final complexity is O(30 * n * logn).
Also gemini mentioned another solution using tries, but i did not bother digging deeper lol.
Why would there be a 50% chance of a random b[i] being a suitable unchanged element?
either y ⊕ x is in a or not.
I guess this might be an over simplification, but I can't see anything that would skew the probability that much from 50/50. it could be 50/50 on average? im not sure.
That's like saying you have a 50% chance of winning the lottery because you either do or don't. I don't see where you got that from.
I get it, it's not convincing, but it's not the same as saying you have a 50% chance of winning the lottery...there is like a billion lottery tickets, but here we have one array, in or out. there should be a way to prove the probability though.
It's funny you mention "1 out of a billion" since $$$a_i \leq 10^9$$$
proved by Accepted I guess 385697542, but I will think about it more.
youre more than welcome to try and hack it.
funny how ur skipped on ur last rated contest :)
I have an observation. There are n elements, but as the editorial says, only 1 element will be the one that was used to perform XOR. So, the probability that that element being ai is 1/n. So, the probability that the 30 numbers you picked having the right element is 30/n. Your solution got accepted so I am wondering if my logic is wrong tho.
Still, I get amazed by solutions that use randomization to get AC. Awesome man!
maybe i should put the update edit at the top lol, but I hacked it (gemini gave the test case), but the test case is not trivial tbh I dont really understand.
From what I could understand, your solution picks some elements and sees if ai XOR that element exists in b array. If not, then that element is not the answer, also, ai can also not be the answer. So, for every number you pick, you either get the answer or you are removing some elements. So, for the next element you randomly pick, the operations are reduced as the size of the array is reduced. So, the loop almost never runs in n square log n time complexity.
yep, exactly. also congrats on reaching expert!
Thanks man! Appreciate it.
The year is 2044, there is a pandemic of a bioengineered virus that causes near instant death, and hacks are still not open for Codeforces Round 1114 (Div. 3)
The year is 2044, there is a pandemic of a bioengineered virus that causes near instant death, and systesting is still not done for Codeforces Round 1114 (Div. 3)
Shouldn't it be hacking phase rn? For div. 3 rounds, isn't hacking phase 12 hours?
Just a reflection of what I tried (and failed on) on a couple of problems, in case it's useful to others.
Problem C2
My solution to C1 was different (based on another problem I had seen where the characters are a-z instead of 0/1). For this problem, note that adjacent equal elements can be freely moved around. Thus, it suffices to keep removing adjacent equal elements from $$$a$$$ and $$$b$$$ (can do this fast by going left to right with a stack) and check if the resulting strings are equal. I feel this approach can't / might be hard to generalize to C2
This was my C1 submission link.
Problem F
When I was trying the problem, I was just trying to solve it for the case where the values are all $$$1$$$-bit (i.e. they're all $$$0$$$ or $$$1$$$).
If $$$k$$$ of them are equal to $$$1$$$, then you can swap a $$$1$$$ with a $$$0$$$ (by performing an operation at a location of $$$1$$$, and by performing another operation at a location that was formerly zero), and thus you can have the ones correspond to any $$$k$$$-subset of the indices. Similarly, by flipping in the first operation, the array will have $$$n-k+1$$$ ones, and you can reach any $$$n-k+1$$$-subset.
I had trouble trying to visualize what this looks like with more bits (for example, in an operation, the $$$i$$$th bits might get flipped, but nothing might happen to the $$$j$$$th bits since it was zero at the index where you operated). It's hard to visualize how the bits interact with each other. I probably should have just written things down on paper, like what happens after two operations (operating on $$$i$$$ and then operating on $$$j$$$). It's probably more clear after writing it down that it's the same as just operating on $$$j$$$ and then swapping indices $$$i$$$ and $$$j$$$.
Can someone explain me for G how the partition should be for k = 3 in this case (it is from test case 2)? Submitted my code after the contest, but before reading the solution.
8
3 7 8 2 8 5 1 3
1 2 3 2 3 6 5
The expected output should be: -1 -1 23 28 31 34 36 37
But mine gives: -1 -1 21 28 31 34 36 37
I have been trying to see where I my original attempt is wrong, but I can´t see how to get 23 unless I understood the problem wrong.
If you put nodes $$$2, 3, 5$$$ in different sets, you can get 23. For example:
$$$S_1 = \{3, 4\}, S_2 = \{7, 6, 2\}, S_3 = \{1, 5\}$$$.
The sets don't have to be connected
Ok that makes a lot of sense thanks
Nice contest ya'll
Want to add for G that there is an alternative solution that runs in $$$O(n logn)$$$ which avoids small-to-large and uses no heavy theory.
This problem focuses on maximizing whilst also fulfilling conditions.
Define an activated node as a node which is maximum within some subset.
The main observation in the editorial is that for every subtree, the number of activated nodes must not exceed the number of leaves within the subtree. This leads to a simple small-to-large idea. This observation tries to maximize while keeping the conditions fulfilled.
However, we can try to "reverse" the observation. Instead of observing subtrees, try observing the leaves/chains. It's obvious that every activated node must lay in different chains. So, what if we start with activated nodes in different chains and try and improve their value. This observation always keeps the condition fulfilled at the start, so we only have to think of maximizing now.
We start with the activated nodes as the leaves. Then we can try an improve by "lifting" an activated node to its parent and check if it's better. We do need to make sure that no two activated nodes overlap, so lift again if the current node is already activated.
One more problem arises, there could be a node that was activated by a certain chain, but would've been better by a different chain. We can imagine a root with two line subtrees, with the root and one of subtrees containing maximum values. If the subtree with the maximum value was lifted to the root, that would be worse than the other being lifted.
The solution comes by priority. We should lift the lowest valued activated node. This works because if a node should've been activated by a different chain, that different chain would've come to the node quicker than our current.
Still however, this solution (while works now) works in $$$O(n^2)$$$. This is because nodes can be lifted multiple times. But, we can observe that a node that has been lifted, should not be activated again (if something is lifted, it was the lowest and can't be better).
Using a priority_queue + DSU combination, we can achieve $$$O(n logn)$$$ and successfully pass the testcases.
My submission: 385714013
Amazing contest!!!
Problem B was horrible. You say maximal contigious. It means you have to replace the block with maximum length for every symbol not all blocks. I spent 1 hour on B if I did'nt i could even slove E or more. If you did the same pls upvote so Setters see that.
In problem D (Silhouette), shouldn't the resulting array $$$a$$$ be [2, 2, 5, 5, 6] for the second test case? It is lexicographically smaller than the one provided by the author.
That is lexicographically smaller indeed, but that array doesnt correspond to array $$$b$$$, because in $$$b_{2}$$$, the shadow is 4, but the sum of elements smaller than $$$a_{2}$$$ in your array is $$$0$$$
I think C1 was easier than B
BUT I think D is harderrr than E , Anyone else feel the same? -> _ -> :(
Thank You
Hi everyone! I am trying to understand the greedy solution for C2. The editorial says that the k-th '1' in the start array must go to the k-th '1' in the target array.
The case for exactly 2 elements is very clear to me. I understand why $$$|A_1 - B_1| + |A_2 - B_2| \le |A_1 - B_2| + |A_2 - B_1|$$$ holds true.
But what if we have more than 2 elements and everything is completely tangled up? If we have 5 or 10 elements, why can't a change in one pair accidentally make the paths worse for some other elements that we didn't touch?
Could anyone explain how to prove that fixing pairs one by one always works for the whole array without breaking anything else? Thanks a lot!
A useful way to approach proofs like this is to ask: "if a solution is not the one we want, can we make a local change that always improves/stays the same?"
Take any matching. If two pairs "cross" (i.e. $$$A_i \lt A_j$$$ and $$$B_p \lt B_q$$$ and we match the pairs $$$(A_i, B_q)$$$ and $$$(A_b, B_p)$$$, try swapping just those two matches. The only thing that changes is those two pairs, and the inequality
$$$ |A_i-B_p|+|A_j-B_q| \le |A_i-B_q|+|A_j-B_p| $$$
shows that uncrossing them never increases the total cost.
So you don't need to reason about all $$$n$$$ pairs simultaneously. It is enough to show that every crossing can be eliminated locally while only improving/not affecting the answer. Repeating this process eventually removes all crossings, leaving exactly the sorted matching $$$A_i \leftrightarrow B_i$$$, which therefore must be optimal.
unable to upsolve system testing takes too much time!
Amazing contest
Yooooooh C2 is shi* problem, still i really enjoyed solving D
yse still thx this contest has been the best one for me so far
Guys In D i got WA on TC 20 CUZ i writed < instead of <=.
AND In E couldn't write a proper edge case.
And because of this i'm 4833th instead 1000th.
Wth should i do?It's really annoying.
NOW My rating become 1164.I could reach at least 1250 if i didn't made this mistakes.
Well at least i saw my mistakes this is also a thing.
Same mistake I have done in D.
@MikeMirzayanov / Contest Authors:
I am appealing the system message stating my solution for 2254D[user:MadCoder_777_18] (Submission: 385661997) coincided with user shreyash_arya (Submission: 385645552).
I do not know this user, and I did not share my code. While I understand the automated checker flagged our solve() functions as structurally similar, I want to point out a few things:
Completely Different Codebases: My submission utilizes a personalized 200+ line template with custom PBDS, anti-hack hashes, and graph structures that I use in all my contests. The other user submitted a bare-bones class-based solution. We have completely different coding styles.
Deterministic Math: The logic for 2254D essentially forces a single path: storing frequencies, checking if the difference between unique elements is divisible by the count, and ensuring strict increases. Like the mathematical progression forces the loop structure to look identical.
The Print Statement: I recognize that we both used (i == n — 1 ? "" : " ") to format the output. This is a common template I have picked up to avoid presentation errors in strict environments.
If my code was scraped from a public online compiler during the contest, it was completely unintentional on my part. I write all my core logic myself. I kindly request a manual review of our submission histories and coding styles, as a human can see these were not copy-pasted from the same source. Thank you.
Can someone give more detailed proof or give me a starting point to why the small-to-large merging works in (log n)? Still a bit confused on why this works...
We can analyze this from the perspective of an individual element (contribution technique).
Consider any specific element $$$x$$$ in the tree. Suppose the set currently containing element $$$x$$$ is $$$A$$$ (in this problem, sets are maintained by a
priority_queue).When set $$$A$$$ needs to be merged with another set $$$B$$$, element $$$x$$$ is extracted from $$$A$$$ and inserted into $$$B$$$ (i.e., $$$x$$$ undergoes a "move") only when $$$\vert{}A\vert{} \le \vert{}B\vert{}$$$.
After the merge is complete, the size of the new set containing element $$$x$$$ is $$$\vert{}A \cup B\vert{} = \vert{}A\vert{} + \vert{}B\vert{}$$$.
Since $$$\vert{}B\vert{} \ge \vert{}A\vert{}$$$, the size of the new set satisfies:
Every time element $$$x$$$ is moved, the size of the set containing it at least doubles (increases to at least twice its previous size).
Complexity Analysis:
priority_queueto another).Therefore, the total time complexity is $$$\log n \cdot \log n \cdot n = O(n \log^2 n)$$$.
I have an $$$O(n \log n)$$$ solution for problem G.
Use a segment tree on the Euler's tour of the tree. On each leaf node, we store the maximum $$$a_i$$$ over all $$$i$$$ partitioned into the same subset as it. Do this for each non-leaf node on the tree, going from bottom to top: find the minimum value among the entire subtree rooted at this node, and update the value of the single leaf node with the minimum value.
See my solution here: https://codeforces.me/contest/2254/submission/385830330
yse or anyone else :)
Could you please clarify the test from problem 2254G - Nightcrawler?
The test (it is number 13 in test 2) is:
And the correct answer is
The tree is the following, the numbers on nodes are number(A_i)
How is it possible to make 3 path totaling 23?
The 3 paths should end at leaves, and one of them should have the root, and it has both 8 and 7 in its path, so the best we can get is 8+8+5=21, not 8+8+7=23.
Am I missing something?
I made the same mistake as you. The key issue is that the elements in a set do not need to form a connected chain— they can be disconnected.
Counterexample:
Optimal answer sets: $$$(3, 4) , (2, 6, 7), (1, 5, 8)$$$
Your sets: $$$(3, 4) , (6, 7) , (1, 2, 5, 8)$$$
Oh, somehow I was sure they were connected.
Thanks!
I think lots of people made this mistake (including me too). It would have been nice if it had been covered by the sample cases.
I had a solution for D but after hacks it got TLE. Could someone tell me why?
My Submission
Same happened to me as well. I am also trying to figure out why I got TLE.
Please take a look.My Submission
You shouldn't use
unordered_map, as it can cause hash collisions, and in the worst-case scenario, the complexity will degrade to $$$O(n)$$$. Changingunordered_maptomapin your code will allow it to pass.Ohh! Thank you so much!
Never usingunordered_mapfrom now.See this excellent editorial by neal for how to use std::unordered_map safely: https://codeforces.me/blog/entry/62393
Thanks for sharing, this is an excellent blog.
It worked. Thanks.
A great contest.
Great contest and nice editorial, but one thing I'm missing in the solution for 2254G - Nightcrawler is an explicit proof that greedily extending the initial solution by adding the largest unused value at each step is optimal.
The idea is intuitive and clearly permissible (splitting a set into two doesn't invalidate any of the constraints), but that's not a proof that it's optimal. Does anyone have an idea how to prove it more formally?
Why can we ignore the corresponding order for J ?
in problem G. Is there any way to solve it by computing the answer top-dowm ? (i mean iterate from N down to the number of leaves)
oh i dont think there is, or it will be very complex
A-G Bengali Solution Discussion
Why do we need small-to-large merging in G? Isn't the information of each subtree stored in the root of it? And we only need to merge the sons of the current vertex. I don't understand the tutorial.(sorry my English is really poor)
Ok now I realized that the vertexes in the subsets may not be connected. I always make stupid mistakes in understanding problems:)
Well, I don't take part in the contest. But I have had an attempt, which shows that I can solve A, B, C1, C2, E. But unfortunately I don't take part in it! But it's really a good contest and very educational.
Guys, i solved E by cutting into pieces... I didn't know how to use binary-search in muilty-set XD
first contest, good experience
can anyone give me better understandable code for G or explian a solution of G.
My solution for D TLEd and I'm not sure why. It worked when I rewrote it into C++. LLMs couldn't figure it out-any ideas? 386133959
Counteris vulnerable to anti-hash hacks as it is a subclass ofdictThe first hint of C1 doesn't make sense. There's a counterexample for it, that is for substring
011. Using the hint, we could trivially changed it into110, but there exist no rules that shows that such operation could be done since the 1st operation requires us to have a string of001and the 2nd operation requires us to have a string of110, both of which are not the same as011.edit1: sorry, my mind didn't really read that the vice versa. then such counterexample are negated. again, I am so sorry for my own stupidity
can please anyone tell me why my solution for D is getting tle on 19th test case
weird thing — using map is not giving tle and unordered_map is giving tle
https://codeforces.me/contest/2254/submission/385799346
看到讨论区B题的思路和我不太相同,这里介绍一下我B题目的思路,如果有问题还请大家指出: 首先在一个连续字符块中,如果字符数量大于1,那么你去删除它是没有意义的:比如aaa你删除其中一个a它最后都可以通过压缩来变成一个a,那么删除操作就是多余的。 那么我们就可以根据这个原理对所给字符串进行前缀和后缀的预处理操作,具体来说就是对一个前缀或者后缀字符块我们不进行任何删除操作,只进行压缩操作,然后记录压缩之后且不去删所留下来的字符串长度。 有了上面两个前缀和后缀数组,那么我们从字符串的第二个位置开始到字符串的倒数第二个位置开始循环,模拟每一个位置被删除后所留下来的最短字符串长度,这里有两种情况讨论,1.如果说被删字符的前一个和后一个字符相同,那么就要对前缀和+后缀和还要减一,2.如果说被删字符的前一个和后一个字符不相同,只需计算出前缀和+后缀和即可,再统计这些数中的最小长度即是答案。 AC代码如下: https://codeforces.me/contest/2254/submission/386454862
thanks
tests of task F are so weak, I've got it by O(n^2) solution with optimization where we firstly see at amount of numbers where i-th bit is active https://codeforces.me/contest/2254/submission/387199371
Why in problem F there is no way that we gonna got array where N items are satisfied condition of xor-sum, but no one of them really turn A to B? Or there is, but tests are weak?
Oops I'm stupid sorry
For D, if we take a test case b = [1 2 3 4], does any valid array a exist, or would it be a -1 in the output?
For D my Python solution gives TLE, it's the same core logic tho ;). Any idea on how we can optimise this
https://codeforces.me/contest/2254/submission/387781222
B felt much harder than both C1 and C2. Very fun contest though :)