shorya1835's blog

By shorya1835, history, 7 months ago, In English

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
  • Vote: I like it
  • +518
  • Vote: I do not like it

»
7 months ago, hide # |
 
Vote: I like it +16 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it +23 Vote: I do not like it

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

»
7 months ago, hide # |
Rev. 3  
Vote: I like it +6 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

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

»
7 months ago, hide # |
Rev. 2  
Vote: I like it +16 Vote: I do not like it

__baozii__ are you being forced to be a tester?

»
7 months ago, hide # |
 
Vote: I like it +7 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

As a tester

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it +27 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it -21 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

hope everyone gets good performance and forget about last round.

»
7 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

What is the scoring?

»
7 months ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

highly appreciated

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

good luck!!!

»
7 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

[deleted]

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

speedforces?

»
7 months ago, hide # |
 
Vote: I like it -8 Vote: I do not like it

orz

»
7 months ago, hide # |
 
Vote: I like it -21 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it -12 Vote: I do not like it

Hope an interactive problem

»
7 months ago, hide # |
 
Vote: I like it -8 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it +11 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    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.

»
7 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

hope to get revenge for yesterday!

»
7 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it -50 Vote: I do not like it

Please don't make problems by Indians

»
7 months ago, hide # |
 
Vote: I like it -49 Vote: I do not like it

Don't make problems again!

We have just a game theory in competitive programming?!

»
7 months ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

Actually game theory forces!!!

»
7 months ago, hide # |
 
Vote: I like it -12 Vote: I do not like it

operationforces.

AND GOT -VEEEEE DELTA

»
7 months ago, hide # |
 
Vote: I like it -27 Vote: I do not like it

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.

»
7 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it +9 Vote: I do not like it

Guess the problem:

"Wrong answer on pretest 3"

»
7 months ago, hide # |
Rev. 3  
Vote: I like it -10 Vote: I do not like it

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

  • »
    »
    7 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    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?

    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it +1 Vote: I do not like it

      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

    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      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

      • »
        »
        »
        »
        7 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        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

        • »
          »
          »
          »
          »
          7 months ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          oh I was able to prove it after figuring out that 2x works by brute force

          see equation here https://mirror.codeforces.com/blog/entry/146147?#comment-1307743

          and notice that 2x can either have same number of digits or one more digit .. both cases work in that equation

          • »
            »
            »
            »
            »
            »
            7 months ago, hide # ^ |
             
            Vote: I like it +1 Vote: I do not like it

            It 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$$$

            • »
              »
              »
              »
              »
              »
              »
              7 months ago, hide # ^ |
               
              Vote: I like it 0 Vote: I do not like it

              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

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    i actually did that, but got wrong answer on pretest3, dont know what that test case??

»
7 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Can somebody explain how did they solve D?

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

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

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    for A neither was it explained when the string is sorted. Only in testcases you were shown that 1100 is not a sorted string.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

any hints for C? very nice problem

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    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......
    """
    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Yes, same, I also figured out this when I had 25-30 minutes left but could not find any efficient solution

    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      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

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    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.

    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      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.

»
7 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

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

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it +2 Vote: I do not like it

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

    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      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

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

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

    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      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

»
7 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Any clues for D?

  • »
    »
    7 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    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?

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    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.

»
7 months ago, hide # |
 
Vote: I like it -9 Vote: I do not like it

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();
    }
} 
  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like 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

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    In fact the answer is x*2.

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    just switch to c++, your life will be much easier

  • »
    »
    7 months ago, hide # ^ |
    Rev. 3  
    Vote: I like it 0 Vote: I do not like it

    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

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    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

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it
    import java.util.Scanner;
     
    public class Main {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            
            int t = scanner.nextInt();
            
            while (t-- > 0) {
                int x = scanner.nextInt();
                long y = 2L * x;
                System.out.println(y);
            }
            
            scanner.close();
        }
    }
    
»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    7 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    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.

    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      yeah I did the same but after 2 WA .... noooo!!!!

    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      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

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    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

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    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.

»
7 months ago, hide # |
Rev. 2  
Vote: I like it +10 Vote: I do not like it

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

  • »
    »
    7 months ago, hide # ^ |
    Rev. 3  
    Vote: I like it +1 Vote: I do not like it

    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*x has more digits than x

    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it +7 Vote: I do not like it

      Let $$$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.

    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

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

    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it +11 Vote: I do not like it

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

    • »
      »
      »
      7 months ago, hide # ^ |
      Rev. 2  
      Vote: I like it 0 Vote: I do not like it

      Thats what I did, y = 2*x.

      x#y = x * pow(10, digits(2x)) + 2x
      
      x#y/(x+y) will be [x * pow(10, digits(2x)) + 2x]/(3x)
      

      So, numerator will always be like this: 10..00.002 which is always divisible by 3.

  • »
    »
    7 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    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.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    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

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

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

    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      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?

  • »
    »
    7 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    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.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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.

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    oh so a1-a2 part of f(a)will decrease.

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    The cost doesn't depend on how many rounds, right?

    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      there will never be more than one round i think.. either alice makes one move and bob ends it or alice just ends it

    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      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.

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    this won't gain anything. l-l = 0 no increase in cost. and bob will definitely end.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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.

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    $$$100\cdots 02$$$ is a multiple of $$$1+2$$$.

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    We will get 3x for x+2x ans 12x for x#2x.

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    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.

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it +6 Vote: I do not like it

    $$$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}$$$.

    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Can you explain D

      • »
        »
        »
        »
        7 months ago, hide # ^ |
         
        Vote: I like it +3 Vote: I do not like it

        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.

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Mathematical solution for B:

    Let’s concatenate x and y: value = x * (10^a) + y

    It should be divisible by x + y. So for some integer k: x * (10^a) + y = k * (x + y)

    Rearranging gives: y = (10^a - k) * x / (k - 1)

    Now, choose k - 1 = x, which implies k = x + 1, and set a = 9 so that the answer is always < 10^9 when x < 10^8.

    Therefore, the final answer is:
    y = 10^9 - x - 1

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    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.

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    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.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

B,print(x*2)

»
7 months ago, hide # |
Rev. 5  
Vote: I like it +3 Vote: I do not like it

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?

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it +5 Vote: I do not like it

    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.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

The system testing is so fast

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
7 months ago, hide # |
Rev. 2  
Vote: I like it +1 Vote: I do not like it

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?

»
7 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Amazing problems!!! Very very thanks!!!

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anyone explain why long long causes RTE on E1?

337837256

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it +5 Vote: I do not like it

    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.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

Спойлер
»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hi, can someone give hint for C?

  • »
    »
    7 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    Hint 1:

    Spoiler

    Hint 2:

    Spoiler

    Hint 3:

    Spoiler

    Hint 4:

    Spoiler
»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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'

»
7 months ago, hide # |
Rev. 5  
Vote: I like it +5 Vote: I do not like it

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.

»
7 months ago, hide # |
 
Vote: I like it +49 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can someone tell why D solution is giving RE?

https://mirror.codeforces.com/contest/2140/submission/337860175

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    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.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

337864326

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

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Where can we report cheaters? I've got alot

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

one good contest, love D so much

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    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

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Very interesting div2, I learned a lot!

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Nice Round

»
7 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Great Contest

»
7 months ago, hide # |
Rev. 2  
Vote: I like it +17 Vote: I do not like it

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.

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    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.

    • »
      »
      »
      7 months ago, hide # ^ |
      Rev. 2  
      Vote: I like it 0 Vote: I do not like 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

    • »
      »
      »
      7 months ago, hide # ^ |
      Rev. 2  
      Vote: I like it +7 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

very good for the solution implication from E1 to E2!