By performing the operation, try to break a block into $$$2$$$ blocks.
The only way to increase the count of blocks is to break a block into $$$2$$$ blocks by performing an operation such that some characters of a block are present at the start of the string and some characters at the end of the string. For us to be able to achieve this, there must exist at least one block with a size greater than or equal to $$$2$$$. But, if in the original string, the first and the last character are already equal, this means a block is already broken into $$$2$$$ block (in some other rotation, it will be one block). Hence in this case the answer will be the score of the original string.
Inshort, if first and the last character of the string are equal, or no $$$2$$$ adjacent characters are equal, then the answer will be score of the original string. Else the answer will be score of the original string $$$+ 1$$$.
Time complexity: $$$O(n)$$$
Code: 363907571
2192B — Flipping Binary String
What is the condition for -1?
If the length of the string is odd and the count of 1 is odd, then and only then the answer will be -1.
First of all, flipping a bit an even number of times is equivalent to not flipping the bit at all, and flipping a bit an odd number of times is equivalent to flipping the bit just one time. So, to make all the bits equal to $$$0$$$, we have to make sure we flip all the $$$0$$$ bits an even number of times and all the $$$1$$$ bits an odd number of times.
One of the ways to achieve this is, if the count of $$$0$$$ bits in the string is odd, then apply the operation on all the $$$0$$$ bits. If the count of $$$0$$$ bits in the string is even and the count of $$$1$$$ bits in the string is also even, then apply the operation on all the $$$1$$$ bits. If the count of $$$0$$$ bits in the string is even and the count of $$$1$$$ bits in the string is odd, then after applying any operation, the count of $$$0$$$ bits will always stay even. But the length of the string in this case is odd which means we cannot make all the bits equal to $$$0$$$. Hence in this case the answer will be $$$-1$$$.
Time complexity: $$$O(n)$$$
Code: 363909084
If an entire magazine is used, then the operation does not change the total damage dealt or the time used by that magazine. Hence, the operation mainly impacts only the last magazine.
For us to be able to kill the enemy using only $$$i$$$ bullets from the last magazine, what is the necessary condition? Also, what would be the most optimal operation for this?
First, calculate the total damage an entire magazine deals, which is sum of the array $$$a$$$. We will have to use at least $$$h/sum$$$ magazines. Now, the remaining health of the enemy would be $$$h$$$ modulo $$$sum$$$. If the remaining health is $$$0$$$, then we don't need to worry about the operation.
If the remaining health is greater than $$$0$$$, then we will try to perform an operation that can minimise the number of bullets required in the last magazine. For every $$$i$$$ from $$$1$$$ to $$$n$$$, we will check if we can kill the enemy using only $$$i$$$ bullets from the last magazine. When checking for the index $$$i$$$, the most optimal operation will always be to swap $$$min(a_0, a_1,\ldots a_i)$$$ and $$$max(a_{i+1}, a_{i+2},\ldots a_n)$$$. If $$$min(a_0, a_1,\ldots a_i) \gt max(a_{i+1}, a_{i+2},\ldots a_n)$$$, then it is optimal to not perform the operation for this $$$i$$$. After performing the operation (or not performing), if $$$sum(a_0, a_1,\ldots a_i)$$$ becomes less than or equal to the remaining health, then it is possible to kill the enemy using only $$$i$$$ bullets from the last magazine. The smallest $$$i$$$ satisfying this condition gives us the most optimal answer.
Time complexity: $$$O(n)$$$
Code: 363909342
How to solve the problem for all subtrees without considering the operation?
Answer of hint $$$1$$$: If $$$cost(i)$$$ represents the cost of subtree with root $$$i$$$, and $$$sum(i)$$$ represents the sum of value of all nodes present in the subtree with root $$$i$$$, then $$$cost(i)$$$ is the summation of $$$cost(j) + sum(j)$$$ for all nodes $$$j$$$ that are children of node $$$i$$$.
Now for the operation, for a chosen node $$$u$$$, once the edge between node $$$u$$$ and the parent of node $$$u$$$ is removed, always choose node $$$v$$$ as the node present in the subtree with root as parent of node $$$u$$$, and having maximum $$$d($$$parent of node $$$u$$$, $$$v)$$$ (distance from partent of node $$$u$$$). Do this for all possible node $$$u$$$.
This problem can be solved in a single DFS on the tree. In the DFS, each node will calculate $$$2$$$ things for it's subtree, cost without performing operation and the maximum cost with operation already performed in the subtree.
For calculating cost without performing operation, as compared to the child, the value of $$$d(r, i)$$$ (distance of $$$i$$$ from $$$r$$$) increases by $$$1$$$ for the parent, where $$$i$$$ are all the nodes present in the subtree of child. $$$d(r, i)$$$ increasing by $$$1$$$ means adding $$$a_i$$$ once, as per the equation of the cost of the tree. And adding $$$a_i$$$ once for all nodes present in the subtree means adding sum of values of all nodes present in the subtree once. So, cost of parent $$$=$$$ summation of cost of $$$j$$$ + $$$sum(j)$$$ for all nodes $$$j$$$ that are children of the parent, where $$$sum(j)$$$ represents the sum of value of all nodes present in the subtree of $$$j$$$.
For calculating the maximum cost with operation already performed in the subtree, what the operation does is, it changes the value of $$$d(r, i)$$$ for all nodes $$$i$$$ present in the subtree of node $$$u$$$ (nodes $$$u$$$ and $$$v$$$ are described in the operation). To maximize the cost, we have to increase $$$d(r, i)$$$ by the maximum possible value. And if the value of $$$d(r, i)$$$ is increased by $$$x$$$, for all nodes $$$i$$$ present in the subtree of node $$$u$$$, it means the cost of tree increases by $$$sum(u) * x$$$. Hence, for a chosen node $$$u$$$, node $$$v$$$ should be the node with the maximum depth in the remaining tree. At this point, if node $$$v$$$ does not lie in the subtree of parent of node $$$u$$$, then it will always be optimal to choose parent of $$$u$$$ as node $$$u$$$ (because this increases $$$sum(u)$$$). We can keep doing this, until node $$$v$$$ lies in the subtree of parent of node $$$u$$$. Hence, if we try performing operation for each node $$$u$$$, and node $$$v$$$ is always chosen as the node with the maximum depth present in the remaining subtree of parent of node $$$u$$$, and we take the maximum cost across all these operations, we will always get the maximum cost of the tree we can achieve. In the DFS, for subtree of $$$r$$$, we only need to calculate cost by performing operations for node $$$u$$$, where node $$$u$$$ are children of node $$$r$$$. For all other nodes present in subtree that can be the node $$$u$$$, the maximum cost with operation already performed in the subtree of children of node $$$r$$$ would have already taken care of this.
Time complexity: $$$O(n)$$$
Code: 363909632
Graph problem?
Eulerian cycle?
Make $$$a$$$ a rearrangement of $$$b$$$ means the frequency of all numbers present in array $$$a$$$ should be equal to the frequency of all numbers present in array $$$b$$$. For this to be possible, the combined frequency of all numbers present in array $$$a$$$ and array $$$b$$$ should be even. If at least one number has combined frequency as odd, the answer will be $$$-1$$$.
Now, if the answer is not $$$-1$$$, let's see how to perform the operations. Create a graph with $$$n$$$ nodes and $$$n$$$ directed edges from node $$$a_i$$$ to $$$b_i$$$. The operation swap $$$a_i$$$ and $$$b_i$$$ means the direction of the $$$i$$$-th edge is reversed in the graph. This means, for each edge any direction is possible. Hence, we can consider the graph as an undirected graph, which we need to convert to a directed graph. In other words, we need to decide the direction of all the edges.
In the directed graph, the indegrees and outdegrees of a node $$$i$$$ actually mean the frequency of $$$i$$$ in array $$$a$$$ and array $$$b$$$ respectively. Our problem is to make the frequency of each number in array $$$a$$$ equal to array $$$b$$$, which means to make the indegrees of each node equal to its outdegree.
Since, the combined frequency of all numbers is even, it means the degree of each node in the undirected graph is even. This means the graph contains Eulerian cycles. Each connected component can be treated like a separate graph (because it is possible that our graph is not a single connected component), and find Eulerian cycle in all these graphs. Keep assigning direction to the edges in the direction used in the Eulerian cycle and hence accordingly perform the operations.
Time complexity: $$$O(n)$$$
Code: 363911188
DP?
Try solving the problem in $$$2$$$ phases. Phase $$$1$$$, when Alice's fish and Bob's fish are not adjacent to each other, and phase $$$2$$$, when they are adjacent to each other.
First, let's solve the problem for phase $$$1$$$ (fish $$$A$$$ (Alice's fish) and fish $$$B$$$ (Bob's fish) are not adjacent to each other):
We will maintain $$$2$$$ separate $$$dp$$$, one for each player. Both the $$$dp$$$ work independently of each other. Each $$$dp$$$ will have $$$2$$$ states $$$l$$$ and $$$r$$$, denoting the fish has eaten all other fishes present in the range $$$[l, r]$$$, and $$$dp[l][r]$$$ stores the probability of this happening (without considering the turns played by the other player's fish). This means, the size of the fish has increased by the sum of $$$b_i$$$ for all $$$i$$$ present in the range $$$[l, r]$$$ and $$$i$$$ not equal to the original position of the fish ($$$x$$$ for fish $$$A$$$ and $$$y$$$ for fish $$$B$$$).
From $$$dp[l][r]$$$ we can go to $$$dp[l - 1][r]$$$ and $$$dp[l][r + 1]$$$. But if both the adjacent fishes (fish $$$(l - 1)$$$ and fish $$$(r + 1)$$$) have a larger size and can't be eaten, then in this case the player's fish gets eaten and loses. Hence this directly contributes to the answer without going to the phase $$$2$$$ (only if due to this the fish $$$A$$$ wins). But in this case, we can't directly add $$$dp[l][r]$$$ to the answer as we need to ensure that the other fish is still alive.
Let's say, $$$dpA$$$ and $$$dpB$$$ represents $$$dp$$$ of fish $$$A$$$ and fish $$$B$$$ respectively, and $$$la$$$ and $$$lb$$$ represent $$$l$$$ of fish $$$A$$$ and $$$B$$$ respectively, and $$$ra$$$ and $$$rb$$$ represent $$$r$$$ of fish $$$A$$$ and $$$B$$$ respectively.
If from $$$dpB[lb][rb]$$$ the fish $$$B$$$ can't eat any of the adjacent fish and hence fish $$$B$$$ is going to get eaten, then
$$$probabiliityB = dpB[lb][rb]$$$
At this point, fish $$$B$$$ occupies subarray of length $$$rb - lb + 1$$$, which means fish $$$B$$$ has played a total of $$$rb - lb$$$ turns. Corresponding to this, the fish $$$A$$$ would have played $$$rb - lb + 1$$$ turns (since they play alternate turns starting from fish $$$A$$$). So, we need to find the probability that the fish $$$A$$$ is not a neighbor of fish $$$B$$$ and fish $$$A$$$ is still alive (fish $$$A$$$ occupies subarray of length $$$rb - lb + 2$$$). Considering fish $$$A$$$ is present to the right of fish $$$B$$$, for fish $$$A$$$ to not be a neighbour of fish $$$B$$$, $$$la$$$ should be at least $$$rb + 2$$$. And for fish $$$A$$$ to occupy subarray of length $$$rb - lb + 2$$$, $$$ra$$$ should be equal to $$$la + (rb - lb + 1)$$$. Hence,
$$$probabiliityA =$$$ summation of $$$dpA[la][ra]$$$ (for all $$$la \ge rb + 2$$$ and corresponding $$$ra \le n$$$)
We can similarly calculate when fish $$$A$$$ is towards the left of fish $$$B$$$. We can maintain prefix sum and suffix sum to get these summations in $$$O(1)$$$ time.
We will add $$$probabiliityA * probabiliityB$$$ directly to the final answer without going to the second phase.
No need to do these things when fish $$$A$$$ can't eat any of the adjacent fish and hence fish $$$A$$$ is going to get eaten, because this increases the answer by $$$0$$$ as we need to calculate the probability of fish $$$A$$$ winning and not the probability of $$$A$$$ losing.
Now, let's solve the problem for phase $$$2$$$ (fish $$$A$$$ and fish $$$B$$$ are adjacent to each other):
For this, we will maintain a single $$$dp$$$. The states of the $$$dp$$$ will be $$$la$$$ and the total number of turns played (combined of both fish $$$A$$$ and $$$B$$$). Since both the fishes are adjacent to each other, from only these $$$2$$$ states we can calculate all $$$4$$$ states ($$$la, ra, lb, rb$$$). In phase $$$1$$$, when fishs $$$A$$$ and $$$B$$$ get adjacent to each other, the corresponding probability $$$(probabilityA * probabilityB)$$$ can be added to this $$$dp$$$ of phase $$$2$$$. If the total number of turns played is $$$c$$$, then in this $$$dp$$$, either we can move to $$$dp$$$ with state $$$c + 1$$$ (and correspondingly the other state $$$la$$$ can also change), or the fish eats the other player's fish, or it gets eaten by it's adjacent fishes. In the latter $$$2$$$ cases, if the fish $$$A$$$ wins, then we can add the probability of this happening in the final answer.
Time complexity: $$$O(n^2)$$$
Space complexity: $$$O(n^2)$$$
Code: 363912044








bro the time limit of problem F is too strict, I got TLE on #58 using the same method.
Unfortunately, n^3 cannot be allowed to pass here.
But also, most code in contest passed in <2 second. Are you sure you aren't writing overly complex code?
nah, I forgot to optimize that part. Thank you for checking.
I solved problem B with the same idea as the solution, probably some minor mistakes. Can anyone help point it out? Thanks.
(Python btw)
u should handle the -1 case in the else statement and the else one in the if , otherwise if there are odd no of ones and odd no of zeroes , it will return -1 , whereas it should have been the third case and zeroes are to be printed
Ohh... Thankss
Ones — odd, Zeroes — odd : Do operations on all zeroes. Ones — odd, Zeroes — even : Not possible. Ones — even, Zeroes — odd : Do operations on all zeroes. Ones — even, Zeroes — even : Do operations on all ones.
Your cases are actually wrong
Does "Ones — even, Zeroes — odd: Do operations on all zeroes" case really needed? Doesn't matter if we do the operations on all zeroes or on all ones
yeah we can do both ways. I was just pointing out to one way to do ops
Try for n = 4 and s = 1000 and n = 6 and s = 111000. we can make all 1's to 0, ur code prints -1
Hmm, I see... I swapped my first condition's position with the last condition. It works. Thanks
3rd condition should be 1st and 1st should br 3rd. In the if else code
if len(ones) % 2 == 1: print(-1) You don't need this case, because of this it is failing. Look at this example: 1110 The count of 1's is 3 but here we can make all 0's with the 0.
Really liked Problem D! Thanks for the contest :)
I confused root-to-vertex and longest-vertex-to-leaf distance and I figured out what happened with like 4 minutes left :(
When someone read problem D it looks more difficult then E but in reality......
in reality E is easier than D(less code), at least in my personal experience.
Yep, but it's Euler algorithm
I didnt know it was euler algo until contest ends.
also I don't know the definition for euler algo.
The problem D overloaded my brain.
Sadly E can easily be solved with Chat GPT 5.2
How do you know?
You can check by prompting it the problem statement.
C was so easy. Idk why I was thinking that swapping will add the difference to all the elements upto i, hence I was not able to come up with optimal swap strategy for each index i. Pretty messed up contest for me.
can you tell me what's wrong in my solution ???
Your code is correct. I don't see any issue in it
thx for reply bro i found the issue. In contest i submitted code with ll sum = accumulate(all(a), 0); instead of using 0ll i used 0 but thought this would not be problem and didn't resubmit
thx for round, very good problems with fresh ideas. Take some of this for own problems.
For E, one doesn't even need to find Euler’s cycle. We can try to pair up all the numbers and turn every problem into another easier problem which every number shows up twice in the combined array of a and b. This can be done by simply sequentially assigning a new number to each pair.
can you please elaborate?
E was straight up euler circuit langauage anyone who has practice cses advanced graoh type wouldve easily solved today
I mean, you needed time to be able to solve. One needed to be quick in ABCD. I finished implementing E only 5 minutes after the end of the contest :(
you could just skip D :(
D was trivial tho
I just read d and skipped it was taking time for me to process what's happening
Solved and coded D in 40 minutes, with 45 minutes till the end, but recursion limit of 200_000 apparently takes up too much memory... I was so close to having refactored it in time, too! Ugh
if u code in python, why did u even think about writing a recursive DFS ? sus
I wasted so much time since I misunderstood the statement for D. :( I thought "a tree with root $$$r$$$" in the formula refers to "the given tree when rerooted at $$$r$$$", instead of "the subtree at $$$r$$$ of the given tree with root $$$1$$$". I only realised this was not the case when noticing that in the sample outputs all leaves have cost zero.
I understood the same. That's why I skipped D in the contest. Then, when I started to discuss the problem after contest with my friends, they told me I had misread it. T.T
This hurts
https://mirror.codeforces.com/contest/2192/submission/363904297
https://mirror.codeforces.com/contest/2192/submission/363906924
I found the mistake right away, but I, sadly, do not have inhuman speed to be able to do it in 2 seconds
B was easier than normal div2s
I was able to solve till C. D is a different beast compared to the others. If possible, please add in voting for the problem (excellent, good, etc.).
c number can be made harder. For example, before reloading, you can swap at most one element.
Problem E: https://mirror.codeforces.com/contest/1385/problem/G
isnt E wayyy more easier than D? But somehow D got x2 more AC than D? Anyone feel the same way?
the hardest thing of D is it’s statement, i guess that 50% of us misunderstood D’s statement, include me xD
E is too classical.
Someone plz hack my solution for E during the contest. just make n = 1e6, a = {1, 2, 3, ..., n — 1, n — 1}, b = {1, 2, 3, ..., n, n}, and I believe the solution will get WA or RE.363902719
for problem D are operations independent or dependent? like does tree get changed after the operation or not?
For 2192C - All-in-one Gun,
My solution: Array a will be sorted in non increasing order in the start, let's say, till the index i, the largest i elements of array a are present in non increasing order. After that the order breaks (at index i + 1).
Let the largest, farthest (from index i + 1) element present at index j. So, my claim is that, if we try to swap all indices (from i + 1 -> j — 1) with the index j (always one of the swapped indices is j), then, we can get the answer.
What's the issue with my approach, getting wrong answer?
Code: 363889728
GOOD (and god hah) contest. I like it. Spent a lot of time for D, and didnt read and solved E and F, while E was easy. My bad
why my code is getting wa for c problem pls can anyone tell ?
~~~~~~ //this is code
void solve()
{
int n, health, k; cin >> n >> health >> k; vector<int> a(n); multiset<pair<int,int>> ms; int sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; ms.insert({a[i],i}); sum += a[i]; } vector<int> pref(n+1,0); for(int i=0;i<n;i++){ pref[i+1]=pref[i]+a[i]; } int ans=0,add=n; // for(auto it : ms){ // cout << it.ff << " " << it.ss << endl; // } // cout << endl; // for(auto it : pref){ // cout << it << " "; // } // cout << endl; int step=health/sum; if(health%sum==0){ ans=step*n+(step-1)*k; cout << ans; return; } else{ int rem=health%sum; ans=(step)*n + (step)*k; auto it = lower_bound(pref.begin(),pref.end(),rem); int dist=it-pref.begin(); add=min(add,dist); for(int i=0;i<n-1;i++){ ms.erase({a[i],i}); // cout << a[i] << " " << i << endl; auto v=*ms.rbegin(); // cout << (v.ff) << " " << (v.ss) << endl; int diff=v.ff-a[i]; if(diff<=0)continue; int l=0,r=n; int found=-1; while(l<=r){ int mid=l+(r-l)/2; int find=pref[mid]; // cout << find << endl; if(mid<=v.ss && mid>=(i+1)){ find+=diff; } if(find>=rem){ found=mid; r=mid-1; } else{ l=mid+1; } } // cout << "found" << " " << found << endl; if(found!=-1){ add=min(add,found); } // cout << add << endl; } } // dbg(add); // dbg(ans); cout << ans+add;}
~~~~~
D is quite easy logic-wise, but I messed up the implementation too badly. I maintained vectors of some 4 things for each child to calculate stuff for the parent. If anyone has any suggestions on where could I have saved redundant computation in my code I'll love that, thanks!
atmostone forces !!
Got stuck on C
In ques. 2192D - Cost of Tree,
My solution: Consider a node nd (we want to calc. answer for nd). If u and v are in different child subtrees of nd, I claim that u must be immediate child of nd, and v must be the farthest node from nd.
If u and v are in same subtree (let's say in subtree of immediate child x), x would have calc. answer for itself, nd can use his answer for its answer calc.
But, getting wrong answer. Someone please help.
Code: 363920169
Accepted now, using the same approach.
Accepted code: 363923515
I didn't read your code but this observation is not always correct. if node u has one child, then you can't do an operation on its child. My initial observation was similar to yours but i noticed the problem while implementing.
you can maximize between the best operation for u (zero of no operations exist) and the best operations in the nodes of u's subtree. you can simply do that by storing the effect of the operation on every node and at every node maximize between its operation and the best operation for its children. and by a node's operation i mean the best operation that can be done while this node is the root of the subtree.
I don't think this observation even holds when you can do operations on children of node u. i think i can come up with tests where doing the operations on grandchildren of node u is optimal. but too lazy to do so xD.
sorry, i didn't notice that you mentioned that you already handle this case.
Is it only me, who find B quite hard compared to the normal div2B :(
I solved E kind of fast, but couldn't prove how to do the minimum number of operations. Unless, after the contest I saw that I DON'T need the minimum number of them!!! It is because in Russian there's only a small non-bold word "not" in the problem statement, that I missed. And in English there are two words "do not", that are harder to miss...
UPD: good problems btw
I got -1 rating change; made 5 wrong sub in C :(
There are another approach to solve E by using 2sat
yes i think so xD
Can you explain details? I'm really curious about 2SAT approach
Looking at your code 363881450 I see that you arbirarily divide the elements into pairs and then say that one of them has to be moved to
aand the other tob. I am not sure why this is garanteed to always find a solution when one exists. Could you (if you know yourself of cource) explain why it is?You are right and I don't know why is it true. Someone allready mentioned it here https://mirror.codeforces.com/blog/entry/151217?#comment-1348871
Thanks
Problem D bonus:
What if the operation doesn't refrain from choosing a node $$$u$$$ outside of the subtree of node $$$r$$$?
What node should we consider?
We would need to consider the node $$$u$$$ outside the subtree of the node $$$r$$$ with the greatest cost. Then, we would need to link that node to node $$$v$$$, which we choose to be the deepest node inside the subtree of node $$$r$$$. Additionally, $$$u$$$ can't be on the path $$$r \rightarrow 1$$$.
How can we do this?
How can we flatten the tree into an array and perform queries quickly on that array?
Use Euler Tour to flatten the tree and use Segment Tree to perform queries
We use a Segment Tree Max and an Euler Tour to flatten the tree into an array of $$$2n$$$ elements. If you don't know what an Euler Tour is, read this.
Then, we would perform DFS from the root, and on our path, we update the values corresponding to that node on the Segment Tree to be $$$-\infty$$$ (or just add $$$-\infty$$$ to them) so that we could avoid taking those nodes. We also want to avoid taking nodes that are in the subtree of node $$$r$$$ so we would add $$$-infty$$$ to the range $$$[in[r], out[r]]$$$ on the Segment Tree.
And we take the max value on the array, link that to the deepest node of the subtree of node $$$r$$$, just like the original editorial, compare that to the case when we take node $$$u$$$ inside of the subtree of node $$$r$$$.
Overall complexity $$$O(nlogn)$$$.
In question D editorial solution line 20-21, can anyone explain what this line means “then it will always be optimal to choose parent of u as node u” ? it may be a typo or i am not understanding it.
Lets say node 1 is parent of node 2, and currently you are thinking about choosing node 2 as u. "choose parent of u as node u" means instead of choosing node 2 as u, choose node 1 as u.
can someone help me check my C :v Bruh i really dont see any issue T_T wrong in test 2 :V in test case 3252
edit: i just relize my wrong :V fixed
problem D is very beautiful, but I didn't have time to submit the code
is it just me or can anyone else not see the code submissions as well, it just shows N/A
Can someone please suggest where I might be going wrong with my code? Thanks!
363959696
hello i have a different way of solving b that thought was interesting:
let the number of 1's & 0's in the original string be x and y, in each turn/move you can go from (x,y) to (y-1,x+1) and (y+1,x-1) if x,y>0, and you want then value of either x or y to become zero(by decreasing it 1 by 1)
so you can set it on the number of 1's but there is a catch since everytime your doing the move you are flipping the spots of x & y at the end the one that you choose to decrease by one each turn might end up on the number of 0's ,
how you can calculate this is if x mod 2 = 0 the end value of x can end up on the number of 1's or if y mod 2 = 1 then the end value of y can end up on the number of 1's if both are true you choose the minimum and if none are true the output is -1
i know i could've explained better but as a beginner i did the best i could if a better programmer sees this and would like to refine it i would love to answer any questions they have
anyways here is the code i wrote during the contest:
This logic works totally fine! I wrote my code the exact same way in the contest. 363862786
what a clean editorial
I like problem D much
Here are my notes and core understanding of Problem E: The inherent even-degree property of undirected Euler circuits is what guarantees the element balance between the two arrays. In the ideal case, the circuit forms a closed ring where every node has a degree of exactly 2, with edges running either a[i]→b[i] or the reverse. In practice, when building the graph, some nodes may have edges in the opposite direction from the ideal, resulting in a non-ideal state. But as long as we track these nodes, we can construct a valid ideal Euler circuit by simply choosing a consistent ideal direction for the edges. Elements can flow freely within the circuit, and thanks to the in-out conservation brought by the even-degree property, they will always end up in a balanced state. My implementation: 363982694
Good round!
in div2 C I couldn't understand the solution so made a prefix sum array while replacing minimum element till with maximum element available after that point. It is accepted but can it be simplified?
Thank You
Man i wasted much time in B