Блог пользователя shorya1835

Автор shorya1835, история, 12 месяцев назад, По-английски

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:

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:

  1. arvindf232
  2. cn449
  3. kotatsugame
  4. Rubikun
  5. abc864197532

Div2:

  1. Astitva_the_mahaan
  2. ProfaSIO
  3. RGB_ICPC8
  4. Tenshi_
  5. expi0i
  • Проголосовать: нравится
  • +518
  • Проголосовать: не нравится

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

As a tester, I completely forgot that I tested this round with challenging and cool problems, and I don't get to participate now.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +23 Проголосовать: не нравится

One of the best div2 on Codeforces I have ever participated in (tested).

»
12 месяцев назад, скрыть # |
Rev. 3  
Проголосовать: нравится +6 Проголосовать: не нравится

I hope to participate in this round in Green, and don't return to gray, and don't get -in that comment.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

As a tester, it’s a great honor that my first time testing was for such an amazing round. Hope you guys enjoy it!

»
12 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится +16 Проголосовать: не нравится

__baozii__ are you being forced to be a tester?

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +7 Проголосовать: не нравится

As a tester, I can assure that everyone will love the high-quality problems :)

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

As a tester

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

As a participant, I wish I could solve 5 or 6 problems so I can reach a new rank.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

Hopefully I could be out of competition in the upcoming div4 :P

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +27 Проголосовать: не нравится

Looking at wakanda-forever's picture, it does not seem like participating is a good idea...

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится -21 Проголосовать: не нравится

As a tester, I can confirm that my testing process looked like Hydrogen Bomb vs. Coughing Problemsetter

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

hope everyone gets good performance and forget about last round.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

What is the scoring?

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

Setters please make sure no errors in statements for this one plis plis

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

highly appreciated

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

good luck!!!

»
12 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

[deleted]

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

speedforces?

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

orz

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится -21 Проголосовать: не нравится

I hope this is not going to be like the last div.2 contest(1048) which was made unrated for all.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится -12 Проголосовать: не нравится

Hope an interactive problem

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

As a participant, I hope to solve ABC quickly and D at the end.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

As a participant,I hope that I can solve first four problems

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

as an unofficial participant, i am proud to announce that one of the problemsetters have a similar avatar image to mine :D

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 ???

  • »
    »
    12 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится +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.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

hope to get revenge for yesterday!

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

Please no Error in statements in questions , please check ,recheck and recheck again . Thanks

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится -50 Проголосовать: не нравится

Please don't make problems by Indians

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится -49 Проголосовать: не нравится

Don't make problems again!

We have just a game theory in competitive programming?!

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

Actually game theory forces!!!

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится -12 Проголосовать: не нравится

operationforces.

AND GOT -VEEEEE DELTA

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится -27 Проголосовать: не нравится

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.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Its been a long time since the last I’ve seen a code forces contest that makes me feel like watching a HunterxHunter episode

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

Guess the problem:

"Wrong answer on pretest 3"

»
12 месяцев назад, скрыть # |
Rev. 3  
Проголосовать: нравится -10 Проголосовать: не нравится

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

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Can somebody explain how did they solve D?

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Problem A didn't clearly mentioned how cyclic shift is happening, problem B was pure math, problem C seems like a observation

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

C was really interesting. If only I had 15 more min. I could've cracked it.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

any hints for C? very nice problem

  • »
    »
    12 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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.

    .... could not figure out how to compute cost efficienctly......
    """
  • »
    »
    12 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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)

    1. if (min(odd)>max(even) then alice will swap with last most odd index to keep the max element with herself.

    2. check if there is some random even and odd index pattern whose delta will be greatest.

    • »
      »
      »
      12 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      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.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

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

  • »
    »
    12 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится +2 Проголосовать: не нравится

    How'd you fix the WA on test 3? I got the logic in 10 minutes but WA 3 was soul sucking.

    • »
      »
      »
      12 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      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

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Wrong answer on pretest 3, for C, idk why?

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

can someone please point out the error in this for question c https://codeforces.me/contest/2140/submission/337820138

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    12 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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!!!

    • »
      »
      »
      12 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      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

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Any clues for D?

  • »
    »
    12 месяцев назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    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?

  • »
    »
    12 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится -9 Проголосовать: не нравится

I am solving 2nd question in java i think almost solved but at the last moment time limit exited error anyone can optimize it.

import java.util.Scanner;
public class B_Another_Divisibility_Problem {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();
        while(t-- > 0){
            long x = sc.nextLong();

            String w = Long.toString(x);
            long y = 0;
            for(long i =1; i<1000000000;i++){
                String h  = Long.toString(i);
                
                long ans = Long.parseLong(w+h);
                if( ans % (x+i) == 0){
                    y= i;
                    break;
                } 
            }
            System.out.println(y);
        }
        sc.close();
    }
} 
»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

ok so what was intuition for A, somehow I struggled with it. Also I solved it I couldn't prove why it gives minimum

»
12 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится +10 Проголосовать: не нравится

My solution for B was 999999999-x. I laughed about it for a bit after moving on to C.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

for the problim C i know that i need to make one move but how i know the beast move pls help me

  • »
    »
    12 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    so what i was doing — move will lead to increase by |r-l| - 2*(arr(l) - arr(r)) in one swap

    based on l < r ,or l is even or odd, r is 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

  • »
    »
    12 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    consider the 4 cases of parities of the swapped indices indepandently and pick the best one

  • »
    »
    12 месяцев назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    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.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

https://codeforces.me/contest/2140/submission/337847728 why my code fails on test case 3 of C

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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".

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

"You should be registered for the contest to be able to submit" (T_T) "Why did you close the joining before I could join?"

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Comment 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:

  1. If l is odd and r is even: $$$Expression = 2 * (a[r] - a[l]) + (r - l)$$$

  2. If l and r have the same parity: $$$Expression = r - l$$$

  3. 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 :(

  • »
    »
    12 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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.

  • »
    »
    12 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

B,print(x*2)

»
12 месяцев назад, скрыть # |
Rev. 5  
Проголосовать: нравится +3 Проголосовать: не нравится

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?

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Could someone please explain how to solve E? Game theory's just too confusing for me. QAQ

  • »
    »
    12 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится +5 Проголосовать: не нравится

    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.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

The system testing is so fast

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

debugged my code for E2 a few minutes after the contest ended T_T

»
12 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится +1 Проголосовать: не нравится

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?

»
12 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Amazing problems!!! Very very thanks!!!

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone explain why long long causes RTE on E1?

337837256

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Gpt is able to solve D (I gave it some help to think but yeah)

Spoiler
»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hi, can someone give hint for C?

  • »
    »
    12 месяцев назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    Hint 1:

    Spoiler

    Hint 2:

    Spoiler

    Hint 3:

    Spoiler

    Hint 4:

    Spoiler
»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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'

»
12 месяцев назад, скрыть # |
Rev. 5  
Проголосовать: нравится +5 Проголосовать: не нравится

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.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +49 Проголосовать: не нравится

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).

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone tell why D solution is giving RE?

https://codeforces.me/contest/2140/submission/337860175

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

https://codeforces.me/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?)

  • »
    »
    12 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится +3 Проголосовать: не нравится

    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.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

337864326

any clue why my code keeps wrong? give me hint plz

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Where can we report cheaters? I've got alot

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Why is my rank in the common standings (15) different from the one that my rating got updated according to (25)?

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

one good contest, love D so much

  • »
    »
    12 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 :)))))

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Very interesting div2, I learned a lot!

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Nice Round

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

how the B problem is 800. it's very difficult for 800

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Great Contest

»
12 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится +17 Проголосовать: не нравится

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 :

$$$ \sum_{i \in C} r_i - \sum_{j \in R} l_j $$$

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 :

$$$\sum_{j \in R} l_j = \sum_{i=1}^n l_i - \sum_{k \in C} l_k $$$

Where $$$n$$$ is the input size, by substitution our formula becomes :

$$$ \sum_{i \in C} r_i - (\sum_{i=1}^n l_i - \sum_{i \in C} l_i )$$$
$$$ \sum_{i \in C} r_i + \sum_{i \in C} l_i - \sum_{i=1}^n l_i $$$
$$$ \sum_{i \in C} (r_i + l_i ) - \sum_{i=1}^n l_i $$$

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.

  • »
    »
    12 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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.

    • »
      »
      »
      12 месяцев назад, скрыть # ^ |
      Rev. 2  
      Проголосовать: нравится 0 Проголосовать: не нравится

      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

    • »
      »
      »
      12 месяцев назад, скрыть # ^ |
      Rev. 2  
      Проголосовать: нравится +7 Проголосовать: не нравится

      "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:

      • $$$l_i \leq x_k \leq r_i$$$
      • $$$l_j \leq y_k \leq r_j$$$
      • $$$x_k \leq y_k$$$

      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.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
11 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

very good for the solution implication from E1 to E2!