Hello, Codeforces!
We are glad to invite you to participate in Codeforces Round 1049 (Div. 2) on Sep/09/2025 17:35 (Moscow time).
You will have $$$2$$$ hours to solve $$$6$$$ problems and some problems will be divided into subtasks. The round will be rated for participants whose rating is below 2100, but higher rated users are also welcome to participate out of competition.
The problems were authored and prepared by shorya1835, Divine_Spark and wakanda-forever.
We would like to thank:
- Sugar_fan for his great coordination.
- Alexdat2000 for Russian translation.
- doofushmirtz, Dragokj03, Shubham_KV and ho-oh, for proposing problems that later weren’t included in the final set.
- Our list of testers for providing valuable feedback: fallleaves01, _istil, Andreasyan, andrei_boaca, __baozii__, IceKnight1093, Tobo, Boboge, temporary1, ButterflyDew, BiggestOtaku, Proof_by_QED, Friedrich, Darko1, satyam343, Welcome24ever, madlogic, MaxBlazeIceInk, harshith_04, weirdflexbutok, milind0110, tridipta2806, chromate00, priyanshu.p and Non-origination.
- MikeMirzayanov and KAN for the great platforms.
Good luck & have fun!
UPD: Score distribution: $$$500$$$ – $$$1000$$$ – $$$1250$$$ – $$$1750$$$ – ($$$1750$$$ $$$+$$$ $$$1000$$$) – $$$2750$$$
UPD2: Editorial has been posted.
UPD3: Congratulations to the winners!
Div. 1:
Div2:








As a tester, I completely forgot that I tested this round with challenging and cool problems, and I don't get to participate now.
One of the best div2 on Codeforces I have ever participated in (tested).
No interactive problem?
I hope to participate in this round in Green, and don't return to gray, and don't get -in that comment.
As a tester, it’s a great honor that my first time testing was for such an amazing round. Hope you guys enjoy it!
yo, how to be a tester?
Bro, you literally doing only 800*, and trying to be tester, why? Try to do 1300* without help, get Expert, and then try to be tester, if it helps with money, or knowledge.
I asked how lol yo overreacting like imma doing rn
I want to give you a real road, not: i'm doing only 800*, so i want to be tester.
Seems like I misunderstood. Sorry and will continue to do 1300
I absolutely have no idea what is going on of this community
__baozii__ are you being forced to be a tester?
I have actually been forced by cf admins to test all rounds :(
As a tester, I want to force __baozii__ to test my round.
As a baozii, _istil please test my round.
As a tester, I can assure that everyone will love the high-quality problems :)
As a tester
controversial but fair enough
As a participant, I wish I could solve 5 or 6 problems so I can reach a new rank.
Hopefully I could be out of competition in the upcoming div4 :P
what is the max rating, with which we can participate in div4?
<1400 , above 1400 rating , you can participate , but you will be out of competition (basically unrated)
oh ok!!
lol sad
Looking at wakanda-forever's picture, it does not seem like participating is a good idea...
As a tester, I can confirm that my testing process looked like Hydrogen Bomb vs. Coughing Problemsetter
hope everyone gets good performance and forget about last round.
What is the scoring?
Setters please make sure no errors in statements for this one plis plis
highly appreciated
good luck!!!
[deleted]
speedforces?
orz
I hope this is not going to be like the last div.2 contest(1048) which was made unrated for all.
Hope an interactive problem
they usually say it in the announcement
As a participant, I hope to solve ABC quickly and D at the end.
As a participant,I hope that I can solve first four problems
as an unofficial participant, i am proud to announce that one of the problemsetters have a similar avatar image to mine :D
a question has been bothering me
next to the question score page, it says that the score you get is based on your "first attempt"
this means that if someone submits a question incorrectly in the first minute and then submits it correctly at 1:59:59, the score for that question will be based on minute 1 ???
no, the score table shows, the score you will get if you accept it at that time on your "first attempt".
in your scenario, the person will get a score which he would've if he accepted it at "1:59" on his first attempt, but because it isnt his first attempt, he will get additional penalty.
hope to get revenge for yesterday!
let's consider this as revenge :D
Please no Error in statements in questions , please check ,recheck and recheck again . Thanks
YES PLS.
Please don't make problems by Indians
Don't make problems again!
We have just a game theory in competitive programming?!
Actually game theory forces!!!
operationforces.
AND GOT -VEEEEE DELTA
This was one of the best Div-2 contests I’ve participated in! Every problem was perfectly balanced and well-designed for the contest level.
Shut up, cheater
Bro wtf use a code formatter. Messing up your formatting will not fool the plag checker anyway.
Not too sure whom to ping for reporting suspicious accounts. shorya1835 Can you do something about this user ambarmishra19?
Skipped solutions, code obfuscation, Java TM, yet their editorial blogs have solutions in C++, etc.
Its been a long time since the last I’ve seen a code forces contest that makes me feel like watching a HunterxHunter episode
Nice to meet you, fellow gentlemen.
The man the myth himself
Guess the problem:
"Wrong answer on pretest 3"
C?
all problems LOL
C :skull:
i got it on both C and E1
bad performance for me .. couldn't solve C.. although I guess I figured Alice will only make one or zero move, but failed to code it. and spent too much time on A and B
Doesn't this question reduces to find minimum in odd and maximum at even index such that their absolute difference of index is maximum? Also further we can check that if max_at_even — min_at_odd + abs(odd_index — even_index) >= n-1, if this suffice then we can swap those elements?
You have to take into account that the distance between the elements also get added to the cost. So ones who are not min and maxes but are way further apart might be a better choice
yeah I spent too much time on A and B ..and saw this pattern in C.. but I couldn't simplify the condition to write code
Yeah B was just out of box, I just multiplied every x with 2 and it somehow worked, not sure how will I prove this
oh I was able to prove it after figuring out that
2xworks by brute forcesee equation here https://mirror.codeforces.com/blog/entry/146147?#comment-1307743
and notice that
2xcan either havesame number of digitsorone more digit.. both cases work in that equationIt can actually be proven with simple modular arithmetic.
since the resulting number is $$$x \cdot 10^d + y$$$ where $$$d$$$ is the number of digits in $$$y$$$. Then $$$x \cdot 10^d + y \equiv x \cdot (10^d - 1) \pmod{x+y}$$$
$$$10^d - 1$$$ is a bunch of 9s hence its always divisible by 3. So if $$$y=2x$$$ then its clear why $$$x (10^d-1)$$$ is divisible by $$$3x$$$
I also tried to prove it, got a simple explanation, x*10^k + 2*x should be divisible by 3x, so it reduces to 10^k + 2 should be divisible by 3 and it will always be divisible coz, if we expand 10^k for any value of k and then add 2 to it, the sum of digits will always be 3 and therefor it will always be divisible by 3
saw the editorial, it has the same explanations as mine
nice.. people who could do it from equation are awesome
i actually did that, but got wrong answer on pretest3, dont know what that test case??
Can somebody explain how did they solve D?
gpt was able to solve d
it was a great competition! problem B was also beautiful and the variety of answers surprised me! but this kind of issue should not be raised in programming competitions
Problem A didn't clearly mentioned how cyclic shift is happening, problem B was pure math, problem C seems like a observation
for A neither was it explained when the string is sorted. Only in testcases you were shown that 1100 is not a sorted string.
I had to guess that by sorted they mean in increasing order only.
C was really interesting. If only I had 15 more min. I could've cracked it.
any hints for C? very nice problem
these are my notes for C:
"""Alice wants to maximize, Bob wants to minimize. Result is cost + alternating sum of array. In a turn they can end the game or they can swap two values, which increases the cost. It is optimal for Alice if this is the maximum value she can achieve. Either because it is the absolute maximum or because it will decrease if she doesn't end. Vice versa for bob: End if absolute minimum or if it will increase if not end now. Swapping adds r-l (indices) to cost, so is in favor of Alice. Alice would want to swap a large value with high odd (0-indexed) index with a small value with low even (0-indexed). This increases sum and increases cost most. Bob can always undo the move of Alice. Alice can always undo the move of Bob. This is advantageous for Alice, because costs keep increasing. Therefore Bob will always terminate immediately. Alice only terminates immediately if swapping reduces the sum. Just need to determine if swapping once any two numbers increases the total value... Added value from swapping depends on left and right value and left and right index.
Yes, same, I also figured out this when I had 25-30 minutes left but could not find any efficient solution
Alice will always swap because if he can't find find a good swap of different parities he will use the same parity and it will increase the cost
From what I could think of.
There will only be 2 interation in total. Because bob will always end the game.
Now the problem is boiled down to how can alice make the best of this one chance she has.
1.She can either swap from max(odd)&min(even)+(take care of index cost as well)
if (min(odd)>max(even) then alice will swap with last most odd index to keep the max element with herself.
check if there is some random even and odd index pattern whose delta will be greatest.
i tried that but the couldn't find the min(odd) and max(even) efficiently since the formula for odd and even would differ depending on whether the odd index or even index is the one larger.
Score distribution can be more better , fact that b is just 2*n and c is kinda tricky (wa on 3), the difference between them is just 250 is very low
How'd you fix the WA on test 3? I got the logic in 10 minutes but WA 3 was soul sucking.
Lets define positive index i if (i%2==0 , in zero based indexing) because if we keep any element here then its weight is positive , same we define negative index if i%2==1
lets define magic as (a0−a1+a2−a3⋯an-1)
now we can always swap 2 elements in positive index or negative index then we will get r-l extra score without changing magic of array this is testcase 2 ig.
now we can swap element at positive index with negative index or negative index with positive index so our magic will change because elements at positive index and negative index is changed.
Now the reason for wa on 3 is testcase 1 and testcase 2 don't have great test to check the conditions for swapping element of positive index with negative index
this is the reason why i get wa
Wrong answer on pretest 3, for C, idk why?
did it
can someone please point out the error in this for question c https://mirror.codeforces.com/contest/2140/submission/337820138
Try the Test Case
Correct Output Should be :- 8 (swap 2nd, 3rd elements) But Your code will give :- 6
code gave 8 but WA on 3...
got it thanks mate
problem a was soo confusing as in, in the binary string where do we even start indexing and then it is not mentioned how exactly the cyclic shifts work, like the example was confusing
I had to spend a lot of time to understand how the cyclic movements work in this problem, as if it were possible to make a more detailed description of how these shifts work, did the testers immediately understand how they work, it seems to me the only thing they do is write under each contest that THIS IS THE BEST CONTEST IN THE WORLD THAT I HAVE TESTED!!!
lmao couldn't agree more i got soo frustrated that i solved b before a and then by the time i came back telegram smarties already made a's rating drop by 100 pts i mean atleast i could've avoided the negative delta today but never the less b and c were nice problems
Any clues for D?
I think it has to do with the fact that for 2n points, pairing the first half and second half in any order is optimal. Assigning each segment an l and r does not change the optimal case. There must be at least n/2 "r" points on the right side of the median, otherwise there are more "l" points so by php at least one of them is unpaired. So we should be able to greedily pair segments with r to the right of the median with segments that have l to the left side of the median. If a segment has its r on the right and l on the left of the median, we can save it for later. At the end we can just pair the saved segments together. Is this right?
Let's say $$$n$$$ is even.
Then you have to choose $$$n/2$$$ $$$r$$$'s and $$$n/2$$$ $$$l$$$'s (independent) such that the answer, sum_choosen($$$r_i$$$) $$$-$$$ sum_choosen($$$l_i$$$), is maximum.
Another way of expressing that is as sum_choosen($$$l_i + r_i$$$) — sum_all($$$l_i$$$). Clearly, you have to choose the $$$n/2$$$ biggest $$$l_i + r_i$$$. That works because the choosen elements will cancel it's $$$l_i$$$'s substraction, leaving the original formula.
You can do it similarly if $$$n$$$ is odd.
I am solving 2nd question in java i think almost solved but at the last moment time limit exited error anyone can optimize it.
can you run it on your machine for 1e7 to 1e8 .. and see if it finishes ? .. like don't take input and just make another loop outside
In fact the answer is x*2.
just switch to c++, your life will be much easier
You can always choose y = 2 . x now if x has k digits then x # y will become x . 10^k + 2 . x which is equal to x . (10^k + 2) and x + y = 3 . x as both of them has a common factor of x and 10^k + 2 is also divisible by 3 (as the sum of digits is 3) so x # y is always divisible by x + y
this is not going to work, i found a solution for this problem in youtube which solved in O(1) link, have a look at it once
ok so what was intuition for A, somehow I struggled with it. Also I solved it I couldn't prove why it gives minimum
Not sure if correct, but I thought that the cyclic thing was more or less equivalent to swapping two values. (The third value is redundant, just pick another zero at the front or one from the end.) Then I used two pointers, one from the left (to find the first 1) and one from the right (to find the first zero). Swap values. Increment ans. Repeat until left >= right.
yeah I did the same but after 2 WA .... noooo!!!!
correct, after realizing this, what I did was just count the number of ones, and since there must be exactly that many ones in the end, finding the number of zeros in the positions where the ones should be gives the answer. You can check my submission 337777147
my intuition was, say i want to move all the 0s behind, now the only cases to consider was 100,101 and 010, now I found that a single shift(based on the triplet we chosse) can make at most one 0 move to one of the first g positions(g was number of 0s we had in total). so I found out the 0s beyond the g positions
ooh interesting.. sounds different from 2 pointer thing
I guessed the solution is the number of zeros or ones that are not at their final positions. It passed but I don't know why...
Create a copy of the string and sort it, now count the number of places the original string is not equal to the sorted string and divide that by 2.
My solution for B was 999999999-x. I laughed about it for a bit after moving on to C.
mine was 2*x .. but spent too much time to figure..
how did you find your solution.. i just wrote brute force till 100 and figured that it works even if
2*xhas more digits thanxLet $$$y$$$ be a $$$k$$$ digit number. Then the concatenation of $$$x$$$ and $$$y$$$ is equal to $$$x \cdot 10^k + y$$$. The goal is then to make $$$\frac{x \cdot 10^k + y}{x + y}$$$ an integer. Notice that I can manipulate the expression into $$$\frac{x \cdot (10^k-1) + x + y}{x + y} = \frac{x \cdot (10^k-1)}{x + y} + 1$$$, and if $$$x+y = 10^k-1$$$, the expression will be an integer. So I just used the largest possible $$$k$$$, which is $$$9$$$ in this problem.
brilliant !!!!
thanks for sharing.
We define the operation as: $$$x # y = 10^{\log_{10}(x)} \cdot x + y$$$.
This must be divisible by $$$(x+y)$$$, i.e. $$$10^{\log_{10}(x)} \cdot x + y = k \cdot (x+y)$$$.
Solving for $$$y$$$: $$$y = \dfrac{x \cdot (10^{\log_{10}(x)} - k)}{k - 1}$$$.
Now just brute force over $$$k$$$ until $$$y \lt 10^9$$$.
shouldn't it be
log10(y)in the exponent.can this brute force tle ??
Also can $$$y = 8x$$$
First: $$$10^k x + y = (x+y) + (10^k - 1) x$$$
Let $$$y = t \cdot x$$$ then need to $$$(10^k - 1) \vdots (1+t)$$$. Left part always $$$(10^k - 1) \vdots 9$$$, so we can took $$$t = 8$$$
wow so many variations.
Thats what I did, y = 2*x.
So, numerator will always be like this: 10..00.002 which is always divisible by 3.
same but I saw this after finding out
2xwith brute force lolcool!! I should have done this only! It took me so much time figuring this simple thing :/
I also spent too much time to figure it out.. but then ran brute force ..
omg someone solved it like me!
I did just enough 9's to have 1 digit more than the input but I didn't realize it until I read this comment rofl.
Although it seems that you actually reached that conclusion by thinking, I just generated all y <= 10x that work and saw a pattern.
for the problim C i know that i need to make one move but how i know the beast move pls help me
so what i was doing — move will lead to increase by
|r-l| - 2*(arr(l) - arr(r))in one swapbased on
l < r,orlis even or odd,ris even or odd.. .i was making some conditions .. but couldn't code it..I am guessing it all converges to simple condition which I was not able to see
consider the 4 cases of parities of the swapped indices indepandently and pick the best one
I tried with odd_left, odd_right, even_left, even_right, but couldn't get it to work. Is this what you mean with the parities?
I tried to do the following, but still didn't work for me: If we swap odd index with odd index (or) even index with even index, sum won't change, only cost changes. So, max change from such an operation will be last_odd_idx — first_odd_idx(1).
Other useful swaps(l,r), l<=r will be l-odd,r-even and l-even,r-odd: Case1: l-odd, r_even - change in sum = 2(a_r — a_l) + (r-l) = (2*ar+r) — (2*a_l+l) Case2: l-even, r-odd - change in sum = 2(a_l — a_r) + (r-l) = (-2*ar+r) — (-2*a_l+l)
So, I calculated suffix max for r+2*a_r on even r's and iterated over odd l's and r-2*a_r's on odd r's and iterated over even l's.
Not sure why I'm getting WA on test 3.
https://mirror.codeforces.com/contest/2140/submission/337847728 why my code fails on test case 3 of C
For C, in the first test case, I think it would be optimal for Alice to swap 1000 with 1000 or 1 with 1, instead of ending immediately.
That does not increase the cost or the sum of the array, but it requires Bob to play optimal thereafter. Optimal play from Bob from there would be to end immediately*. So Bob ends the game instead of Alice, which is a small nuance.
*If Bob does not end the game immediately, then he would increase the cost with 1, and Alice can undo his move, again increasing the cost with 1. By not ending immediately, the sum has increased with 2.
oh so
a1-a2part off(a)will decrease.The cost doesn't depend on how many rounds, right?
there will never be more than one round i think.. either
alice makes one move and bob endsit oralice just ends itthat is right for the first case,but not the second
wdym
9 9 9 9 9.. Alice swap1 and 5...f(a)becomes13... Bob stops ..is my thinking wrong
My bad, I misunderstood the problem. But I somehow managed to pass it anyway :)
whoa !!! crazy ...
The cost only depends on left and right index, which are both the same in my example, so cost does not change.
But, my point is, playing optimal would be to not end the game if you can get a better result. Alice can get a better result, by continuing, so even if Alice does not improve her game, Alice should continue it. If Bob makes a mistake, Alice has a better result.
I get it, but Alice knows Bob is never wrong
this won't gain anything. l-l = 0 no increase in cost. and bob will definitely end.
Is the statement in problem D supposed to imply that you cannot choose (i, j) if it would not give you a valid choice of x_k and y_k, i.e. you cannot choose (i, j) such that r_j < l_i? Obviously, that would never be optimal anyway, but I was a bit confused while reading the statement because it stated "choose any two unmarked segments".
"You should be registered for the contest to be able to submit" (T_T) "Why did you close the joining before I could join?"
Could anyone prove why 2*x always work for B? I just ran a brute force for some values and saw it works for all of them.
$$$100\cdots 02$$$ is a multiple of $$$1+2$$$.
We will get 3x for x+2x ans 12x for x#2x.
x#2x = 12x. Damn, that's some magical stuff.
My bad :D so i solved B with mu luck ig
the rule for division by 3 is that the digits for the number all sum up to 3. When you set y to 2*x, and then concatenate it, you can write it as x * 100002, where the number of zeros is the number of digits of y. So now you have to check whether x + y, which is 3 * x, divides x * 100002. 100002 is divisible by 3 and x is divisible by x, which makes the solution valid.
$$$x \operatorname{\#} 2 x = 10^k x + 2 x = (10^k + 2) x$$$ is always a multiple of $$$3 x$$$, as $$$3 \mid (10^k + 2)$$$ holds true for all $$$k \in \mathbb{N}$$$.
Can you explain D
My solution is slightly complex. The only thing you need to observe is that by merging $$$[l_1, r_1]$$$ and $$$[l_2, r_2]$$$, the maximal length of the new segment is $$$1/2 [(r_1 - l_1) + (r_2 - l_2) + |(l_1 + r_1) - (l_2 + r_2)|]$$$, which is equal to half the sum of the lengths of the two segments plus the distance between their midpoints.
Managing the largest midpoints and smallest midpoints should work. Enumerate which segment to discard when $$$n$$$ is odd. For the rest, please refer to my code.
Sorry for my poor English.
Mathematical solution for B:
Let’s concatenate
xandy:value = x * (10^a) + yIt should be divisible by
x + y. So for some integerk:x * (10^a) + y = k * (x + y)Rearranging gives:
y = (10^a - k) * x / (k - 1)Now, choose
k - 1 = x, which impliesk = x + 1, and seta = 9so that the answer is always< 10^9whenx < 10^8.Therefore, the final answer is:
y = 10^9 - x - 1Comment on Problem C
For Problem C, I realized that Bob will always stop the game at the first turn, so the problem essentially reduces to how Alice can maximize her gain with single opportunity.
I formulated the maximize target as:
$$$r - l + (a[r] - a[l])((-1)^{l+1} + (-1)^{r})$$$
Depending on the parity of indices, this simplifies into three cases:
If l is odd and r is even: $$$Expression = 2 * (a[r] - a[l]) + (r - l)$$$
If l and r have the same parity: $$$Expression = r - l$$$
If l is even and r is odd: $$$Expression = 2 * (a[l] - a[r]) + (r - l)$$$
However, I am stuck on how to simplify this expression. I tried a brute-force approach over all possible (l, r) pairs, but it resulted in TLE :(
You'll find that in this expression, with lfixed, the part involving rdepends only on ritself. use the suffix maximum to find the optimal rfor any given l.
Split the contribution of $$$l$$$ and $$$r$$$ apart. For example, $$$2 \times (a[r] - a[l]) + (r - l) = (2 \times a[r] + r) - (2 \times a[l] + l)$$$. Keep the minimum of $$$2 \times a[l] + l$$$ while scaning the array.
B,print(x*2)
PLS FIND OUT MISTAKE what I did in C:
--Notice that both people can undo the previous move while the cost increases. Bad for bob.
--Transform original array to v[i] -> 2 * v[i] + i as it encodes the function's increase or decrease
--Now, the answer is max(argmax(even_index) — argmin(odd_index), n % 2 == 0 ? n — 2 : n — 1)
I don't see a fallacy here? Can someone please point it out?
Edit, found it(for my reference)
Oversimplified the problem. I thought that by swapping j and i, we can reduce the casework of even and odd stuff. How am I oversimplifying everything lately?
Waaaaaw I've been on cf for more than a year but this is the first time that system testing is done within 30 mins since the contest ended. Mike sir either buffed the servers or I guess we didn't have much submissions this round
Could someone please explain how to solve E? Game theory's just too confusing for me. QAQ
You can solve E1 by brute-forcing every single initial state in O(n^2*2^n) with bitmask DP, since performing an operation always puts you into a state with shorter sequence length(there might be a faster way). For E2, you can use a combinatoric idea, where you calculate, for each i, the number of sequences such that x >= i. To do this, notice that if you only want to check whether x >= i or not, it only matters whether each element is >= i or < i. So you can iterate over each bitmask of length n, where a 1 in the mask means the element at that position is >= i and vice versa. If the DP from your E1 solution says that the current bitmask is a win for alice, you should add (i-1)^(n-popcount) * (m-i+1)^(popcount) to the current sum, since that would be the total number of sequences that correspond to that mask. This gives you an O(2^n * m) solution, which can be optimized to O(nm) if you notice that in our earlier calculations, all we really needed was the popcount of each mask.
Got it! Thanks for your help~
The system testing is so fast
debugged my code for E2 a few minutes after the contest ended T_T
I have seen 3+1 solutions for B so far
2*x
8*x
999999999-x (number of digits x9 — x )
My question is, how many relatively distinct solutions does this problem have?
Amazing problems!!! Very very thanks!!!
Can anyone explain why long long causes RTE on E1?
337837256
You allocate approximately 352 MB of memory ($$$2^{20} \cdot 21 \cdot 2 \cdot 8$$$ bytes) on stack. C++ executables on Codeforces allocate 256 MB for stack space (see Codeforces command lines), so your program causes stack overflow, hence RTE.
Gpt is able to solve D (I gave it some help to think but yeah)
Hi, can someone give hint for C?
Hint 1:
The game will always go like this: Alice chooses some l and r and does a swap. Then, Bob will necessarily end the game. Convince yourself that this will indeed be the optimal set of moves.
Hint 2:
Alice can either swap with l and r having same or different parity. If l and r have the same parity then the f(a) only increases by r — l.
Hint 3:
Otherwise, if l and r have different parity then: If l is odd then a[l] will go from contributing +a[l] to -a[l]. This means the net f(a) will decreases by 2 * a[l]. Similarly, if l is even then a[l] will go from contributing -a[l] to +a[l]. f(a) will increases by 2 * a[l]. Similar set of changes happen for r.
Hint 4:
Any l also contributes -l to f(a), and r contributes +r to f(a)
Couldn't get C, I overcomplicated B so so sooo muchh...
I was solving math equations today XD Would like to share:
I found out that the equation boils down to: y = (x * (10^digitsOfY — C) / (C — 1) Where C could be any constant, and digitsOfY would be count of digits in Y
Now as we can see that the 2nd term in numerator can never be divisible by C — 1 unless we have digits set to 0 (not possible), so x has to be divisible by C — 1
So I found the factors of x, checked for c — 1, put them in equation, if I find a value of y, return it.
All of this instead of 'x *= 2'
Here's a link if anyone's interested: https://mirror.codeforces.com/contest/2140/submission/337804366
My solution to D:
When $$$n$$$ is even:
Notice that the answer is of the form $$$-l_{i_1} -l_{i_2} -... - l_{i_{n/2}} + r_{i_{n/2 +1}} + ... + r_{i_n}$$$ for some permutation $$$i$$$. This means for every segment you either pick the left endpoint to subtract or the right endpoint to add. Swapping your choice of endpoint results in your answer changing by either $$$\pm(l_i + r_i)$$$.
Imagine starting by choosing the left endpoint for all $$$n$$$ segments. Now you need to pick $$$\frac{n}{2}$$$ right endpoints from segments to take. It is easy to see that it is optimal to swap segments with the largest $$$(l_i + r_i)$$$.
When $$$n$$$ is odd:
Using the solution for when $$$n$$$ is even, you can compute the answer trying to leave out every point in $$$O(n)$$$ time.
Proud to present a screencast, it is the first time I managed to have a div2 #1 recorded.
(No problem A solve because I accidentally leaked something at the first minute of the screencast).
Can someone tell why D solution is giving RE?
https://mirror.codeforces.com/contest/2140/submission/337860175
https://mirror.codeforces.com/contest/2140/submission/337809781
Got unsucessful hacking attempt for trying to push this out of bound using a string containing only zeroes/ones.....
Should not this be runtime error (I understand the garbage will most likely not be 0 or 1, but should not it be runtime error in hacks?)
l++ will stop at l = n as s[n] = '\0'. r-- will access content before the string buffer which can lead to RE but it is very likely that the memory before the string buffer is also just 0s. So, it will trip at r = -1 and stop too. Even if it is not 0s, it is most probably not just a bunch of '1' chars. Not all invalid memory access leads to RE.
337864326
any clue why my code keeps wrong? give me hint plz
Replied in the other thread: https://mirror.codeforces.com/blog/entry/146218?#comment-1307864
Dear Codeforces team,
I received a warning regarding similarity in my submission. I want to assure you that I solved the problem by myself without copying or sharing. Since the approach is quite standard, the resemblance with another code might be coincidental.
I respect the contest rules and kindly request you to reconsider this warning.
Thank you for your understanding.
Where can we report cheaters? I've got alot
For example here. It's from this blog.
Do they really consider it for plag checking?
Why is my rank in the common standings (15) different from the one that my rating got updated according to (25)?
Because of [trusted participants only]
one good contest, love D so much
i don't think so first 20 minutes no approach for a , then try b then i just guess the thing that's why b happen in 41 minutes then again try for a after some WA it gets AC,B was just waste of time atleast they can give a good implementation not this kind of bullshit
It was very very lucky to me.
I tried E1 because I think this would be easy to think and yeah, I've got it.
And when I tried to implement, I've got the idea in E2. I did not solve D during contest.
And this was very lucky, because today, I try D 2 times and get 2 wrong answer :)))))). It would be terrible if I decided to solve D instead of E1 last night :)))))
Very interesting div2, I learned a lot!
Nice Round
how the B problem is 800. it's very difficult for 800
Great Contest
For problem D, a very "neat" way of reaching the greedy conclusion is by expanding the formula of the chosen segments' sum. Let's name the of chosen segments $$$C$$$ and the rest be $$$R$$$.
Our formula is :
If we manage to eliminate contribution of group $$$R$$$ from this equation it will be easy to select group $$$C$$$ to maximize this expression. To do so we can expand the second term, based on this substitution :
Where $$$n$$$ is the input size, by substitution our formula becomes :
Now it's clear to see that maximizing this expression is equivalent to maximizing sum of right and left of a segment, since summation of all lefts is constant.
That's actual very neat. Though I didn't understand,
this implicitly force the set that supplies the pairwise min-lefts (R : rest) to be the complement of the set that supplies the pairwise max-rights (C : chosen segments). But that is not true: in a pair, the same segment can be both the min-left and the max-right.
I get the solution through above formulas. But intuitively unable to picture it.
Case :
n = 4 [0, 100] [0, 99] [51, 51] [50, 50]Answer : (51 + 51) + (0 + 100) — (0 + 0 + 51 + 50) = 101
But the optimal answer : 100 (segment 1 & 3) + 99 (segment 2 & 4) = 199
"This implicitly forces the set that supplies the pairwise min-lefts ($$$R$$$ : rest) to be the complement of the set that supplies the pairwise max-rights ($$$C$$$ : chosen segments)."
That's correct. The problem statement says that a new segment $$$[x_k, y_k]$$$ must satisfy these conditions:
So, $$$x_k$$$ lies on one of the segments, and $$$y_k$$$ lies on the other. This means you can't pick the left and right such that they are included in only one of the segments. So yes the same segment can be both min left and max right but you don't get to pick both.
Subject: Plagiarism Detection Appeal for Submissions 337833357 (2140E1) and 337841099 (2140E2)
Hello @shorya1835,
I received plagiarism flags on my submissions 337833357 (2140E1) and 337841099 (2140E2). I want to clarify that both were my independent work, and I did not share my code with anyone. The similarity between my solutions and others arises because the editorial approach to these problems is quite standard, which naturally led to many nearly identical implementations across contestants.
Although according to my knowledge i think there no exact problem that existed before the contest although yes there are few problems that uses similar data structure for example if you see the previous contest 2138 so problem c1 and c2 have same data structure usage apart from these.
Although if needed i am sharing my approaches for both the problem for proof:
My approach / logic for 2140E1:
Use bitmask DP to represent the current configuration of size p.
Precompute which indices are allowed (allowedByP[p]).
Transitions:
If it’s Alice’s turn (maximizer), the state is winning if any allowed removal leads to a winning child state.
If it’s Bob’s turn (minimizer), the state is winning if all allowed removals lead to a winning child state.
Shrink the bitmask when removing elements (by shifting).
At the end, count how many patterns lead to Alice winning and compute the result modulo 1e9+7.
This is exactly the structure explained in the editorial, which is why many solutions look very similar.
My approach / logic for 2140E2:
Bitmask DP: Represent states by bitmasks of length p (remaining piles).
Precompute allowed removal positions for each length p.
If it’s Alice’s turn, mark the state winning if any allowed removal leads to a winning child state.
If it’s Bob’s turn, mark the state winning if all allowed removals lead to a winning child state.
Shrink the mask when removing elements.
Counting configurations: After DP, count how many bitmask states of size n are winning depending on the number of 1-bits (S[t]).
Final sum computation: For each pile value v = 1..m:
Compute contributions using powers of (m — v + 1) and (v — 1) (precomputed to avoid TLE).
Multiply by S[t] and sum modulo 1e9+7.
This is also the exact editorial solution structure, which again explains why solutions across languages look so similar.
I kindly request you to review my case. Both solutions were written independently during the contest, and I did not share them with anyone. The similarities flagged are a result of following the standard editorial approach to these problems.
Thank you very much for your understanding.
Sincerely, Anichesschamp1008
Hello, I have recently received multiple plagiarism/copying warnings on my submissions. I want to clarify that I did not copy from anyone. During this contest I had to use online compilers because I was out of town, which might have caused some similarity in code formatting. All my solutions were written by me independently.
I respect the rules of Codeforces and competitive programming, and I request the admins to kindly review my case.
Thank you.
viveksingh135002 is my handle.
Similar problem lol. they skipped my submissions and marked as out of the comp.
Problem: 2140A My submission: 337841406 Similar flagged submission: 337779407 (user: david_jeldi) Explanation: I wrote my code independently. My version uses unusual variable names (banana, donut, cookie), which is my own style. The algorithm is straightforward and short, so many independent implementations may look almost identical. I did not copy from or share with anyone. If needed, I can provide my local editor history and timestamps as proof. It’s possible that the similarity is due to the simplicity of the problem rather than collaboration.
very good for the solution implication from E1 to E2!