Hello, Codeforces!
I'm glad to invite everyone to Codeforces Round 1008 (Div. 1), Codeforces Round 1008 (Div. 2), which will be held on Mar/10/2025 17:45 (Moscow time).
You will be offered $$$7$$$ problems in both divisions 1 and 2, and you will be given $$$2$$$ hours and $$$30$$$ minutes to solve them.
Both divisions contain at least one interactive problem(s). Please look up the guide if you are unfamiliar with them.
I'd like to give my utmost thanks to
satyam343 and Kaey for coordinating this contest, preparing statements/tasks, and donating a problem.
The testers: Dominater069, Friedrich, Rhael, Mysticmage45, tigerBoss101, Non-origination, TyroWhizz, _istil, LipArcanjo, Error_Yuan, Proof_by_QED, ffao, NerfThis, ikrpprppp, Murinho, WLZ, irmuun, Tainel, Chaska, marianoferesin, ankan2526, Darshan_Bhangale, kolomig0r, dougalves, profchi, Lucina, 0I0acOJleHbKa, Marckess, Saman., N_z__, PeruvianCartel, sammyuri, A_G, catology, arvindf232
My friends Rhael for an illustration, Punpun (no CF account) for one task, and a shoutout to Mysticmage45 for no particular reason.
Alexdat2000 for the Russian translation.
MikeMirzayanov for Polygon and Codeforces platforms.
I hope everyone will indulge in the tasks blissfully.
Score distribution
Division 1: $$$500-1000-1500-2250-2250-2500-3000$$$
Division 2: $$$500-750-1250-1750-2000-2750-3500$$$
Congratulations to the winners!
Division 1
Division 2








For the first time Div2 is unrated for me!
[deleted], sorry for a mistake
I think there is a bug in registration because everyone able to register for div1
you can register , but you will be "out of competition" that means unrated
No, you cannot register (even as out of competition) on the division you're not rated in when it's a Div. 1 / Div. 2 parallel round. Out of competition registration can only be done when there is no rated division for you at the same time, but everyone in Div. 1 / Div. 2 round has a rated division for them. This should be fixed soon.
ok mb
I see satyam343, I wait for a sweaty binary search problem
I'm guessing a counting problem
Is it 1998C - Perform Operations to Maximize Score?
That time I was naive to think it's easy div2C...
Yeah, absolutely cringe and unbalanced div2C. Many reds spent a lot of time debugging it, only to hear from satyam343 afterwards, "just learn binary search".
I finally upsolved it after 2h+ of coding and debugging...
This is not only binary search, very implementation punishing also.
As a tester, I tested.
why are there so many new accounts registered a couple minutes ago registering for div1? are they bots from ai companies / research groups?
As a div 2 participant. I'm scared to fight against bots atm.
chuckles I'm in danger.
Yes approx. 2300, but why are less than CM able to even register?
As a tester, this contest was a div2-only round when I tested it.
omsincoconut Please suggest which topic I need to practice to participate in this round , if possible .
I can't tell you that. Just wait and see.
Ok sir
Am i even eligible for div 2?
In div 1, 2 contests, div 2 is <1900 rating and div 1 is >=1900 (However, in div 2 only contests, div 2 is considered <2100)
ohh, thanks for the help mariza
No problem. Good luck if you participate!
As a tester, do not forget to turn on your computer before the round
As a contestant if I see a permutation construction B, I will skip :)
Expecting increase
Is the contest rated ?
As a tester, I can ensure that omsincoconut is not a real coconut.
Finally, the first rated round of this month!!!
I'm a Chinese senior high school student. I really want to participate in this contest, but the contest will last until 1:15 a.m. in China, while I have to go to school at 7:30 a.m. Should I sacrifice my spare time to join the competition?
yes
Just do, 2:15 am here! And yes I have classes tomorrow morning~
Bro a master in high school that is crazy
Bro I finish the competition by secretly bringing my computer and phone to schoo :) My teacher did not catch me :)
Sometime you have to pay for what you love :)
Based
I'm on like 3hrs of sleep but we gamble
Site is way too slow,nothing is loading.
it's getting unbearable atm
thank u for these soundtracks
Arcaea Round
someone just tell me how to do div2-c.
Scratched my head for more than an hour.
There is a solution that missing number is in position 2 and is bigger than all of the numbers in the array
Yea true, either 1 or 2, 2 always works 1 can sometimes work and needs a check. Also we should mention that in sorted array, not any
Hint: sort the input array, you calculate the second-last element by sum(odd) — sum(even)
and what will be the sequence?
Best by example in this problem:
My solution will be:
Final output:
What if that second-last element is already present in b? Wouldn't that create duplicates?
Hint: it can't happens because my new X always > max(b). Try to think why?
lets say we have 6 3 2 1
so the equation will be 6 = x-3+2-1
6 = x — (greater than 0 (as elements are distinct and sorted))
so x will always be greater than 6 which was the greatest element of all so no chance of clash.
instead of thinking a1 thinking of a2*n by rearrangement
so I took all terms on one side a1-a2+a3-a4... .. now because order doesn't matter we only have two choices.. we can have a term with positive sign or negative sign missing
because we wanted everything to be different .. I thought we can remove a2 and its value will be a1 + (a3-a4) + (a5-a6) + (last term) .. now if this sequence was reverse sorted.. then this sum will be greater than a1 .. hence greater than every thing / different than everything
so that is what I did
Nice Approach!!
Btw, How did you get the intuition that this may work ?? (As an beginner I'm very curious :) )
I am sorry but I don't have any answer apart from experience/practice.
For me it is also a hit-and-miss, sometimes I spend hours thinking of some observations and fail :( :(
Thanks
how to solve E ? what are the questions you ask ?
Ask $$$n = 0101010101$$$ and $$$n' = 1010101010$$$, then calculate $$$sum - 2 \times n$$$, you will get $$$x \oplus y$$$.
how to 1E
i got to the point where you can make a set of indices $$$i[1], i[2], ..., i[k]$$$ darker iff $$$i[u] - i[u-1]$$$ odd for all $$$u$$$ but idk how to continue from there
My line of thought was the following:
We can simulate a subarray with the following code
Then I realized that this is something to do with prefix sum balance of the subarray. The problem turns into finding the maximum prefix sum — minimum prefix sum of the subarray taking b[i] = i % 2 == 0 ? a[i] : -a[i] (there's a graph interpretation for this that I've learned and seen from quite a few past problems) and now it shouldn't be that hard for you.
What was the second query supposed to be for Div2 D? Also, how come so many solves on F?!!
I knew exactly what to calculate in Div1C, but couldn't know how to calculate it efficiently :(
Who would have thought a scammy game ads could've been this hard of a problem?
Any hints for div2D?
it was greedy , idk why i coded and it worked :)
For each +X, we calculate its contribution to the total answer, which is the number of times clones of it at the end. We start with +1 to simulate the presence of two individuals at the beginning.
We maintain two variables, L_i and R_i, to track the maximum number of duplicates we can achieve when progressing through gates i to N, where we choose either the left or right gate at the ith gate, respectively.
If the ith gate is an addition (+), then: L_i = L_(i+1) (No clones are made, the same guys move to the next gate)
If the ith gate is a multiplication (* X), then: L_i = L_(i+1) + (X — 1) * max(L_(i+1), R_(i+1)) (Here, X — 1 duplicates are created, which can choose between the next gates based on which will maximize the number of future clones)
The updates for R_i are done in the same way.
Finally, sum the contributions of all + operations to compute the total answer.
for 2F/1C I got some mathematical expression but couldnt simplify, so I generated F(N, K) = answer when you have K 0's, and via OEIS i realized that F(K) is a 3rd degree polynomial and just used brute + oeis to find the coefficients. How are you supposed to do it normally???
You answer is great.I never mind this way。
Couldn't optimize D. I distilled it down to its optimal to either use all extras in lane 1 or all in lane 2, Couldn't think of a greedy heuristic to use to prune down to the optimal path so ended up being 2^n TLE. I'm guessing it has to do with the fact that the multiples are either 2 or 3, but ran out of thinking time
My solution was just O(n^2) greedy. It's always optimal to either send all extra to lane 1 or lane 2. There are 4 cases,
Case 1: + x, in which case it is always optimal to send extras to lane 2.
Case 2: x +, in which case it is always optimal to send extras to lane 1.
Case 3: + +, in which case you just accumulate more extras.
Case 4: x x, in which case you either send extras to the one with the larger x, or look down the line to find the first x in lane 1 or lane 2 (similar logic if they are the same).
This makes sense. I think where I messed up was attempting to calculate the extras allocation too soon.
Your solution delays the decision by carrying over the extras further down the road to always make the decision where it matters. Thanks for the explanation.
Why do you just assign the "extra" towards the lane where you find greater multiple down the line or the first multiple? Wouldn't you look over all the multiples and calculate effective multiple and decide overall which lane will be the best choice?
did he mean, if we have *2 *3 don't look down the line, just add accumulated players to *3?
yeah
Can you explain case 4? what do you mean by look down the line to find the first x in lane 1 or lane 2?
Basically to decide whether to move extras to lane 1 or lane 2, you want to see which one of them has a multiplication that comes first after that point. All of the steps are easy to prove so I would recommend trying to do that. If you need help you can ask me.
By the way, you can optimize case 4 so that it's not the bottleneck of your solution. There's two routes you can take for the same multiplier subcase: either you treat them as extras that doubled or tripled (and still keep the same non-commital aspect of "looking down the line"), or you preprocess "looking down the line". The first of these routes is actually very similar to your Case 3 (you don't commit people to one lane and just accumulate extras). Either way, you get an O(n) solution.
yeah bur O(n^2) easily passes and its easy to implement.
I made a greedy solution guess for div2 D without proof and it passed pretest, now fingers crossed for system test.
Also I struggled with what question B was actually trying to say.
Edit : yikes !!! div2 D passed system test. I am not proud, but I will sleep happily now.
No way, greedy worked for D? I calculated and it got disproved in the given TCs, can you tell me what you mean by greedy here?
yeah waiting for system tests first ha ha .. not sure it is going to make it
but my greedy was do brute force BFS for all possible state but at a layer only take max values in front of a gate.. so every layer of BFS can only have max 2 states. eg if possible state in front of gate were (5,3), (4,2), (1,19), (2, 10)
max in front of operation 1 is 5 and max in front of operation 2 is 19
so I only take (5,3) and (1,19) to next BFS level ..so my BFS don't explode to 2^n
not sure of correctness though .. fingers crossed
I see, all the best.
did not understand, please elaborate your approach in detail
you can check my submission for the code..
I will only give brief idea.. first idea was to do 2^n BFS .. basically at every step ... get all states ... so what are these states
eg. if 1st gate has
Apeople and 2nd hasB.. and operation on 1st gate isop1and on second isop2... this state is denoted by{A,B}then results after going through the gates will be
op1(A)andop2(B)... now diffs are d1 and d2 whered1 = op1(A) - Aandd2 = op2(B) - B, these diffs are new people which appeared , and these need to be rearragned for remaining gatesnow first assumption I made was we send all people to same gate .. so possible next states are
{A+d1+d2, B}( we send all new people to gate 1) and{A, B+d1+d2}now if we do this completely every layer will have
2^(layer)states and overall2^nI made another assumption that I will pick only 2 states in a layer which gives me maximum people in front of a gate .. so now every layer has at max 2 states, which is what I did. example of this choice is in previous comment.
what I am not sure is why this assumption is correct, but because it passed given test cases I submitted to try my luck.
ok got it. i was thinking of the same approach but not with 2 states at each level/gate, i was thinking of trying all the possible distributions of the newly appeared persons that came out of the gate.
what is your idea of greedy?
Suppose you are currently in i-th gate. Now consider closest gate j where i<j and one of its door has 'x'. Then you always have put your extra people on that lane. Because once you reach that gate you will have duplicate of extra people(so you can place it on other lane if you want) but if you were to put it on the other lane then you would only have the amount of extra people you made.
yikes I completely miss this idea... Thanks
Div2 D was like its almost in my hands but i cant catch it haha
And why can't they be sent after the competition?
What do you mean
Can't I make a package after the round!
You can, but it will not be a part of the competition, its an independent submission
You cannot submit solution while system testing is pending/running. Simply wait till the system test is completed.
Why is test 1 of div1 b not an example
A contest with an interesting interective problem! I have solved my first Div.2E :)
how to solve E $$$??$$$.
Try to query 01010101... and 10101010... to find x and y.
Do you actually determine x and y from that? I queried 0000…0 and 01010…1 and just determined how many times each bit is set in x and y together.
In fact there are many possible x and y for this problem, and I found one of them. Then I directly calculate the final answer with those x y.
E can be solved using the C++ programming language.
I hope this helps!
Hello guys, I have kind of just started. Can someone please tell after the contest ends where can I find the solutions for it...
and are there any good subreddits, discords or telegram chats that discuss the solutions after the contest is over
they will publish editorials after some time , you can keep checking this post for the contest announcement https://mirror.codeforces.com/blog/entry/140357
they will attach the link to the editorial at the bottom of this post
and yes people share some ideas on youtube.. search for contest name ie 'Codeforces Round 1008' on youtube
thanks a lot!
How to solve C in div 2?
my thoughts
https://mirror.codeforces.com/blog/entry/140357?#comment-1253756
thank you, your solution was easy to understand
Please read editorial as well , it can have a different / better solution
I liked some of the problems.
Not the worst contest. The statements were mostly clear and easy to understand.
The maximum for D is actually slightly under the limit.
The actual maximum is n=30 with a +1000 gate at the start, followed by 29 x3 gates. With 2 sides, your answer comes out to 2002*3^29 which is slightly above 1e17, while 64-bit integer limit is over 1e19.
how did you dp? dp[L][R][i] where L is number of people in lane 1 and R is number of people in lane 2 and i is the ith gate/level we are at.
1000* (3^29) can be the worst case for L and R which are maybe like ~1e15 so to calculate all dp states wouldnt that give a TLE?
Track the number of people going to the left gate, right gate, and also track a variable for people gained last round (call these people "assignable". There are only 4 types of possible gate combinations: (x,x), (x,+), (+,x), and (+,+). Observe the situation going from the final gate (call this gate n-1) to the front gate (call this gate 0).
At the final gate, a simple greedy reveals the best option (just assign everyone whichever gate gives you the most people). Call this choice c, and let dp[n-1] = c. How does this help us find the best option for any previous gate?
Observe the (x,+) and (+,x) cases. In these cases, assigning p people to a x2 gate gives us p extra assignable people when going to gate n-1, and 2p people for the x3 gate. Let's consider the (x,+) case for simplicity. If you want to assign people to the right side on the next step, it is actually optimal to assign p people to the left side first, gain p extra people from the x2 (or 2p for x3) than if you had directly assigned to the right side, and then use those p people and assign them in the step following. Doing so gains you p people on the left side and either maintains or increases the number of people on the right side by p, as compared to directly assigning everyone to the right side.
You can actually use the same logic to show that assigning to the x3 multiplier in (x2, x3) or (x3, x2) is weakly dominant to the strategy of assigning to x2 (you gain p extra people to assign to any side compared to x2, and you can then assign those people to the other side if needed). In these cases, dp[i] = (side with mult or better mult), regardless of the value of i.
This leaves us with the cases of (x,x) with the same multiplier and any (+,+) cases. Observe that no matter where we apply our people, the contribution of our p assignable people does not affect how many people we have later. This means we actually have to consider the next step to see what the optimal assignment is. In other words, dp[i] = dp[i+1] in this case.
By backtracking all the way to dp[0], we can then assign people correctly based on the dp shown.
Let's revise the idea in the dp solution. Observe that the dp is only relevant in the cases where dp[i] = dp[i+1]. Thus, we simply do not assign the people when it is not necessary, and only consider them if we are passing a x2 or x3 (and multiply them accordingly). The only time we assign people to a side is when there is a clear best option for assignment, i.e. when dp[i] = (some choice not necessarily equal to dp[i+1])
why is my implementation wrong? I trusted the problem statement with the fact that it is guranteed that can have at least 1 such A such that a is the difference of the sums of B and C where both B and C have size n and are made from the array given in the problem. I did swaps to check for a valid one but it gave RTE on test 2 implying there was no such A :(
CODE-
checked your code, the reason why it fails is that it tries to do missing = (large values) — (small values). However, there are some cases where missing can be one of the large or small values. The simplest example is 1 = 2-1, and there are others where it instead hits one of the large values like 6 = 5-3+6-2.
Remember that every person can only go through one of the gates in each pair, so in your example the number of people would triple for every pair of gates they go through. As there $$$30$$$ pairs of gates, the total number of people at the end would be $$$2\cdot3^{30}\approx4\cdot10^{14} \lt 2^{49}$$$, which easily fits in a (signed)
long long.I understand it like this.
Gate1: (1, 1) -> (3, 3), $$$ \delta=4 $$$, adjust to (1, 5), we touch only new people when adjusting lanes
Gate2: (1, 5) -> (3, 15), $$$ \delta =12 $$$, adjust to (1, 17), we touch only new people when adjusting lanes
$$$...$$$
After Gate30 the number is much larger than $$$2^{64}$$$
Notice how the total number of people after each gate is $$$3$$$ times larger than before the gate. This must be true, as every person went through a
x 3gate. This means that after gate $$$n$$$ the total number of people will be $$$2\cdot3^n$$$. After gate $$$30$$$, we have $$$2\cdot3^{30} \lt 2^{49}$$$ people, which is not larger than $$$2^{64}$$$.Indeed, thank you.
Just a bug in my testcase, unfortunately.
Today contest was surprisingly good ngl. C was just hard enough but not too hard.
While D is still beyond me, I try greedy but failed.
did you dp for D? if so what was your dp state?
I tried dp backwards by keeping the lane to which I allocate people (keep the lane with the largest multiplier if at the current lane multipliers are equal or there is only addition). The approach kept giving WA2.
After the contest I solved using forward dp with the state (left count, right count, current delta). Here you should carefully apply the delta only when you necessarily have to. That is when resulting deltas from applying the previous delta are different when the previous delta is applied to the left and to the right.
Wow, 2F/1C was chatgpt-able
Why is Div 2C of all satyam343 rounds unrealistically hard? I think it should be at least 1800-1900 today.
my predictors tell me:
B : 919, C : 1417, D : 1717, E : 2023
Not only is C <= 1800, but so is D
your skill issue is not the problemsetter's fault
I think your perspective is in the minority though. I also found C really difficult out of nowhere.
I did not give an opinion. I gave a fact. The rating of C (according to very reliable predictors) is estimated at 1400.
You can find it hard personally, but claiming its a hard problem overall is bullshit.
When you realize that C is trivial for large N, it becomes much easier. You really don't have to consider any n > 2.
I agree, I found B easier than A in the div1 round. I'm not sure if my solution for A (div2C) is correct.
how do these predictors work ?
i am not privy to the details, but they are mostly accurate (and CF ratings are usally way more messed up). One predictor is the TLE bot which is available in the Ericchto server.
oh ok , thanks for the reply.
that bot's not working rn
To make it easier consider that all n > 3 are pretty straightforward.
Sort the array. Now you can separate the full array into two arrays, one called "negatives" and one called "positives", positives being the array of the largest elements.
Note that they are pairwise distinct, so the smallest difference between "positives" and "negatives" will be greater than or equal to (n^2) (you can prove this via pigeonhole principal). Meaning you can just greedily calculate the difference between these arrays and the difference will always be larger than the largest element.
The hardest part is handling the edge cases with a small "n"
I'll predict today div2C is 1400 — 1500. Dunno what is D tho... but for sure it's beyond me (1800+)
Are you sure Round 979 C is hard? It is rated 1100
I was unable to solve it and it really made me sad too(though I wasn't feeling very well tbh)
I got you omsincoconut, you are a big fan of bitmasks
If you solve A-C slow you're projected as a specialist.
If you solve A-C fast you're projected as candidate master.
I think this is a bit too much variance for the exact same problems solved
I made 3 wrong submission in A (skill issue) I was 1400th when I solved C and 2500 now
Na I solved ABC fast today.But my rating change is -1.I think D was gamechanger as usual
This is precisely what i'm talking about, you're a mid expert, and there are specialists who solved the exact same problems as you and lost significantly more rating than you
Maybe I am wrong, but I am pretty sure that just Fast-Solving A-C will never make you a Candidate Master.
A costs even more time than D for me..
I solved A-D with somewhat slow C/D (still beating the max you can get with ABC of 3000 points) and I didn't quite get CM performance (my perf was 1895). A-C fast is probably 1750-1800 performance if I had to guesstimate a range of where it would be.
please give editorial soon, I think there was some neat idea for div2 E interactive problem because there were only 2 queries , but I couldn't think of any working solution during the contest :(
Ask 0b101010101 and 1010101010
yeah I thought about it... but wasn't sure how to interpret the result.. I need better understanding of bit stuff -_-
I want to thank you for your hint and along with https://mirror.codeforces.com/blog/entry/140357?#comment-1254569
I was able to upsolve it.
Arcaea is a great game. However this round is not so great as Arcaea.
But I gain rating from this contest, that's good enough.
Next time please give a formulized form for fold. In E I was thinking you should fold everything on the left to the right, but it turns out that you can just fold part of it(which made 01110 can be done in one operation). Wasted half and an hour.
Looked at the leaderboard for 10 minutes.sumit876 Found this cheaters:
jgiitkgp (problem F) — 309822713 (100% cheater)
d_vaibhavi_singh (problem F) — 309844418 (I think its cheater i am not sure)
2mato_pota2 (problem F) — 309818888 (100% cheater)
sumit876 (problem F) — 309807587 (100000% cheater)
I bet there are a lot more in top 1000. Please take action against these cheaters!
A lot of people have the same beginning at least of code, written clearly by AI, saying "Compute modular inverse using Fermat's little theorem" or something like that
Its insane how these people are so dumb they didnt even erase the comments provided by chatGPT.
It answered that why so many people passed F rather than E in the contest. When I have solved E, I found those who have passed F is more a lot.
Well, apparently chat gpt knew how to solve problem F :)))
Tests for div1A are weak. My contest solution was the following:
put the largest $$$N$$$ values as positive and the rest as negative. If that sum is not valid, for each number between 1 and 40 (I chose this upperbound without thinking too much), try to add it to the array and brute force over all permutations to see if any of them is valid.
This approach breaks in many cases, like the following:
Hack
Also, for div1C I couldn’t get the O(1) formula for the answer on time, and after contest I asked ChatGPT and it gave me the formula right away :(
Can you hack mine too? I did the same first step but if it doesn't work I simply random shuffle until it works.
I think the checker for problem C testcases is not correct, please look at this submission
309853299 It says "wrong answer More than one number not found in b". but b = {20, 1} and my answer is a = {19, 20 1}, so i don't think the feedback is right.
NVM, I found what's wrong, sorry
Do you understand, that this round was a complete failure? C has maximally ugly solution that isn't supposed to be in Div2 C and D isn't much better. One author can't make a good round bcs he just can't discuss problems with anyone and they are were bad.
Not true, they can discuss problems with the coordinator and testers.
Get good bro
I really liked Div2 C:
In order to make sure that the new number being added is unique, it's simplest to try for something less than the smallest or larger than the greatest number in the array.
Since, 1 is the smallest number and it can be present in the input, we can really only go larger. The number is permitted to be upto 1e18, while input is limited to 1e9 so this is another hint of the possibility of doing this.
Now, consider that we have found our new number to be X. We can say try to say that:
(X + S1) - S2 = AmaxThis is equivalent to the given condition by placing A1 = Amax and putting the terms of the two parts at odd and even indices.
Now, we can try to make
X > Amax.X = Amax + S2 - S1Since,
S2is sum ofNterms each of which is atleast 1, andS1is sum ofN - 1terms, it is clear thatS2 - S1 > 0is possible. We just have to choose appropriateS1andS2. It is simplest to choose the firstNelements asS1and the nextN - 1elements asS2. All that's left is rearranging them in the appropriate order.An implementation is here: https://mirror.codeforces.com/contest/2078/submission/309808272
In problem div2C for the array 1 20 my code outputs 1 20 19 on the 19th case of the test case 2 and the verdict is wrong answer
can someone explain please??
the submission link:
your 19th answer is 2 3 1
Really enjoyed the problems, thanks to the problem setters. Was able to solve div2E just about 5 seconds after the contest ended, I didn't even realize that I was reading the output format incorrectly (I thought we have to put exclamation mark before printing answer, like how it usually is in interactive problems, should've read the statement more carefully :P)
We both. LOL
For Div2F/Div1C, is there a way to guess the formula during the contest?
Hmmmmm, could you describe your approach? I was able to progress a bit, but there seems to be no direct way to obtain a solution from just those identities.
Through some "proof by I made a bruteforce in python and the pattern seems to match", I was able to obtain the following unproven formula:
\begin{equation} \sum_{j = 0}^{\Delta}\binom{x}{j}\binom{n — x}{\Delta — j} = \binom{n}{x + \Delta} \end{equation}
This expression let's us calculate the number of subsequences with the corresponding delta (actually, I've swapped out the x's, so really here it's more like the number of 0s). However, I have been unable to progress from there since any associated expressions end up being to janky (like, we could use the sum over $$$\frac{\Delta^2}{4}\binom{n}{x + \Delta}$$$, but the division is just too out of place (and in any case, completely wrong) and I've yet to find a proper way to even simplify out the inner part).
It's too much to describe in a single comment, but basically, first we realize that score(l, r) = floor(f(l,r)^2/4) (due to that x(c-x) thing i described earlier) and f(l,r) = cnt_1 — cnt_0.
Now, if we have X ones and Y zeroes (X+Y=n), we get sum over all possible ways to select ones and zeroes as SUM_i (<= X) SUM_j (<= Y) floor((i-j)^2/4) * C(i X) * C(j Y) (by iterating over all possible amount of 0s and 1s in out subsequence).
Now all you have to do is expand (i-j)^2 (handle even and odd separately), move things that depends on i out of the inner sum and use the fact that SUM_x C(x j) = 2^j, SUM_x [x*C(x j)] = j*2^(j-1), SUM_x [x^2*C(x j)] = (j+j^2)*2^(j-2).
How would you handle the even and odd cases separately? It seems to me that if we try to split the sum in terms of it's even and odd counterparts for the $$$\Delta = |i - j|$$$, then we would lose the ability to use the aforementioned properties. But apart from that, your method is very clear, thank you!
For even, floor((i-j)^2/4)=0.25(i-j)^2=0.25S^2
For odd, floor((i-j)^2/4)=0.25((i-j)^2-1)=0.25(S^2-1). This is because (i-j)^2 = 1 (mod 4) if (i-j)=1 mod 2.
If we group S^2 together, we're left with -1 * sum over i-j=odd. This is equal to the amount of subsequences with odd length (all subsequences with even length have an even difference between 1s and 0s, and vice versa), which is 2^(n-1).
have a doubt why you are not considering j to be less than i
I do. The double sum goes over all i in [0, X] and j in [0, Y]. This does include both i less than j and i greater than j.
What was the intuition behind Div1E? How to explain that for single subarray answer is sum of two maximum prefix balances
Read https://mirror.codeforces.com/blog/entry/140357?#comment-1253892
Basically at the start of the process you have range [0, 0], during the process you have a range of sums [l, r] and the events of having to create new operations to be used happens when the sum gets higher than r or lower than l. Graphically, you start at (0, 0), go to (1, a[i]), then (2, a[i]+a[i+1]) and so on while maintining the topmost and lowermost point you've reached. In the end, the cost will be how much you've streched the range so it's the topmost point you've reached (maximum prefix sum) minus the lowest point you've reached (minimum prefix sum).
Edit: added a badly handdrawn representation of what I mean on paint
please release editorial
You always have to choose $$$n$$$ or $$$n+1$$$ numbers to add and the others to minus, let just choose these numbers by random. 309787629
Div2D I wonder why the greedy approach that adding the additional people into the nearest lane where mul[l] and mul[r] differ is right. Can anyone help me
Also editorial when
Let's say you had A people if left lane, B people in right lane before some operation, and that operation gave you L people total to be arranged. You put C people to left lane and L-C to right lane (where 0 <= C <= L):
Left lane: A people, some operation, C people
Right lane: B people, some operation, L-C people
Now lets say you see a next operation "+ X * 2" — other operation will follow the same logic. So after this operation you will get X+(B+L-C) new people to arrange:
Left lane: A people, some operation, C people, operation "+ X", 0 people — total this lane A+C people
Right lane: B people, some operation, L-C people, operation "* 2", 0 people — total this lane has B+L-C people
Remaining to arrange: X+B+L-C people
So if you had C=0, you would have X+B+L number of people to arrange, now lets say you take 0 <= D <= L people and put them to left lane:
Left lane: A people, some operation, 0 people, operation "+ X", D people — total this lane has A+D people
Right lane: B people, some operation, L people, operation "* 2", 0 people — total this lane has B+L people
Remaining to arrange: X+B+L-D people
If you compare this outcome (with C=0) to the outcome before (with any C) you can see that changing D to be equal to C these outcomes will be equal in number of people in left lane, equal in number of remaining people to arrange, and right lane is not worse (B+L >= B+L-C). So having C=0 and changing D you could have equal or better outcome compare to any other value of C
Other operations are the same, core trick is to delay arrangement and see which strategy dominates — there will be always one greedy best strategy
In Div2 C, I am getting WA on pretest 2, (test case 19) which is n=1, a = {1,20}, and my answer is {19,20,1} ,which is correct according to me, but wrong according to test cases, 309845177, IMG1 IMG 2 IMG 3 PLEASE HELP !!!
I think your output on testcase 19 is
1 3 2.19 20 1is your output on testcase 18.omsincoconut, you put a confirmed cheater, Manasvi, in top 5. I think for at least the top 5, you could've checked their submissions. Would that be possible?
why do you think this user cheated ?
their code for C has AI variable names and comments
oh ok, thank you.
I have a pretty straightforward solution for C which was accepted during the contest.
First we re-model the problem. We have a1=a2-a3+a4....-a(2n+1). We re-write this as a1+a3+a5+...a(2n+1)=a2+a4+a6+...a(2n). Let p=[a1,a3,a5,...a(2n+1)] q=[a2,a4,...a(2n)]. We sort b in descending order, push first n+1 elements into p and the last n-1 into q. Therefore our task is now reduced to finding an a(2n) such that a1+a3+a5+..a(2n+1)=a2+a4+a6+..a(2n).
Claim : a(2n)=(a1+a3+a5+..a(2n+1))-(a2+a4+a6+...a(2n-2)). We have to prove that a(2n) lies between 1 and 1e18 and also it is distinct from all a1,a2,..a(2n-1) and a(2n+1)
Since each of a1,a3,a5...a(2n+1) is greater than a2,a4,...a(2n) by construction, it implies that a(2n)>0. It is also not difficult to see that a(2n) would be upper bounded by 2e14.
To prove its distinctness, assume without loss of generality that a1 is the largest number. Re-writing the equation above we have a(2n)-a1=(a3+a5+..a(2n+1))-(a2+a4+...a(2n-2)). Since there are n-1 terms in each expression on the RHS and again by construction, we have each of a3,a5,..a(2n+1) is greater than a2,a4,..a(2n) the RHS>0 . Therefore, a(2n)-a1>0 or a(2n)>a1. Since a(2n) is greater than the largest of a1,a2,...a(2n-1),a(2n+1), it must be distinct from all numbers.
Therefore we have constructed a=[a1,a2,...a(2n+1)]
Note that the approach of push largest n elements into p and the next n into q would not have worked, mainly because we cannot prove that the number obtained would be distinct.
Apologies for the bad formatting
where can i find the solution ? thanks,qwq
editorial is not yet published, we will have to wait, which is very sad.
the link for editorial will be added to this post only .. not sure when.
My solution for Div 2F/ Div 1C, after some calculations, I found a simple formula for the sum of the scores over all non-empty subsequences s. The formula is ((a-b)^2 + (a+b) — 2)* 2^(a+b-4). here 'a' is count of '1's and 'b' is count of '0's, after this, the query part is very simple, just keep track of a and b, then calculate the answer using formula . CODE FOR REFERENCE.. 309928086
After some calculation? Yeah only if chat gpt does it for u
cant find link to editorial?
not yet released I think, we will have to wait a bit longer.
There are some crazy solutions involving DP and functions for div2/D. Mine was quite simple, just start from the last gate and check at which gate should the additional units go. Definitely x3 is better than x2 which is better than addition. if there are of same precedence (at i'th gate) then send them to the same gate as the prev. (i+1'th gate) one. This can be maintained in a boolean array. Now start from the beginning with (1,1) and keep transferring the units according to the array.
Here is the Java solution: https://mirror.codeforces.com/contest/2078/submission/309920626
You can try to prove it informally that it works. The only case that can cause issue that if both the lanes in the last gate have same precedence (i.e. both offer addition or same multiplication). In that case you can send the additional units it to any of the gate it won't change the answer.
One more thing to observe is that when we are transferring additional units. we transfer ALL the units. I think it's quite obvious! if it's not then dry run a few test cases.
Loving this Div.2. One of the best in a while!
I don't mind div2F the meaning of this question.Maybe I have caught a cold,my brain is non-thing.This formula don't mind,help me.
I submission my friend code,in by time,but i have not mind
this question....Have a brain non//
mind is understand ,ee
Task D is super interesting! I see people use BFS, Greedy and DP.
There are so many unique solutions for this.
i solved div1A/div2C with random because why not
the random solution is very fun to do it is my first time solving a problem this way
when solution
oh man, still no editorial, hope we get it soon.
I want to upsolve interactive problem div2 E ... can someone share some ideas around it ?
We focus on how many
1s are in each bit position across $$$x$$$ and $$$y$$$.Divide the bits into two groups: odd-indexed and even-indexed.
Setting specific bits to
1can isolate every bits' contributions.Then: Ask 01010101.... and 10101010.....
thank you for the reply, I will try to solve it with this information
thank you again for your hint, I was able to upsolve it.
Where's the solution???@omsincoconut
I don't think we will get editorial in this life XD
Guys you forgot to wrtie the editoriol
Editorial person after writing the questions and declaring the winner
How to solve Div2 D?
I wrote my ideas here but I don't have complete understanding / proof of correctness
https://mirror.codeforces.com/blog/entry/140357?#comment-1254049 ,
I am also waiting for editorial to get better understanding
is editorial of this contest is released ??
Yes
By when can we expect to have the editorial?
where is the solution?
It's been 2 days editorial is still not up yet!
Editorial 404
Finally it has come
I may die before the editorial. I want to know how to solve D. Please.
Finally some meaning to the game I see as advertisement
0/10 round