MohammadParsaElahimanesh's blog

By MohammadParsaElahimanesh, 4 months ago, In English

Salam !

Here is the editorial for Codeforces Global Round 31. We hope you find these solutions helpful. We also have prepared a special editorial with step by step hint, examples, tables, and walkthroughs which is available here.

2180A - Carnival Wheel

Idea: AmirrzwM, MohammadParsaElahimaneshPreparation: MohammadParsaElahimanesh

Solution
Implementation

2180B - Ashmal

Idea: AmirrzwM, MohammadParsaElahimaneshPreparation: MohammadParsaElahimanesh

Solution
Implementation

2180C - XOR-factorization

Idea: MohammadParsaElahimaneshPreparation: MohammadParsaElahimanesh

Solution
Implementation

2180D - Insolvable Disks

Idea: AmirrzwM, MohammadParsaElahimaneshPreparation: AmirrzwM

Solution
Implementation

2180E - No Effect XOR

Idea: AmirrzwMPreparation: MohammadParsaElahimanesh

Solution
Implementation

2180F1 - Control Car (Easy Version)

Idea: MohammadParsaElahimaneshPreparation: MohammadParsaElahimanesh, AmirrzwM

Solution
Implementation

2180F2 - Control Car (Hard Version)

Idea: MohammadParsaElahimaneshPreparation: MohammadParsaElahimanesh, AmirrzwM

Solution
Implementation

2180G - Balance

Idea: MohammadParsaElahimanesh, AmirrzwM, ShayanPreparation: AmirrzwM

Solution
Implementation

2180H1 - Bug Is Feature (Unconditional Version)

Idea: AkulyatPreparation: MohammadParsaElahimanesh

Solution
Implementation

2180H2 - Bug Is Feature (Conditional Version)

Idea: MohammadParsaElahimanesh, AmirrzwM, ShayanPreparation: MohammadParsaElahimanesh

Solution
Implementation
»
4 months ago, hide # |
 
Vote: I like it -135 Vote: I do not like it

first.

»
4 months ago, hide # |
 
Vote: I like it -116 Vote: I do not like it

second

»
4 months ago, hide # |
 
Vote: I like it -94 Vote: I do not like it

Need more contest like this I love today. I hope we also get some similar problems to practice by authors.

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

I'm probably wrong, but in the Div. 2 contests I've followed, that one had the lowest number of people solving Problem C. X_X

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

nice! problem C was hard

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

C should be in the place of F

»
4 months ago, hide # |
 
Vote: I like it -11 Vote: I do not like it

The way this is laid out looks like it was AI generated (as is every repovive editorial). Please tell me that is not that case...

(really what should i have expected from shayan)...

bro you had one job

ok so i put the edi for C in gptzero

and uh

"We are uncertain about this document. If we had to classify it, it would be considered AI generated Probability breakdown 49% AI generated 2% Mixed 49% Human"

atp youre just ragebaiting bro

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

WAforces

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

After removing these disks, we can repeat the same process on the remaining ones. It can be shown that this procedure finds the correct answer and runs in O(n) time.

Then show it.

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

    yea the prefix part is super vague it did work in the contest but I really want the proof.

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

      if it be a larger one and a smaller one(such as break 2 times, one ends at 9, one ends at 8), then we see that
      the first one has answer 7 at 1-10 , and we can make r_10->0, it will be 7+(11-n)
      the second one has answer 6 at 1-9 , so it will be 6+(10-n)<=6+(10-11)+(11-n)<=7+(11-n)
      proof ends.
      note that (a-b) means the answer from a to b(e.t:(1-2)=1, (5-6)=0 or 1, (1-n)=the answer to output)

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

354224877 can someone help me figure out why is this wrong ?

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

Please help in problem C, If n is even then why isn't this solution working?

  1. take k-2 n's
  2. for last 2 element. assume x and y
  • we need to choose x and y such that their xor is n.
  • so first set bit of n to x and second set bit of n to y. For remaining bits, if 0 then give bit 1 to both and if 1 then give 1 to y and 0 to x.

Not able to find the issue in this

My solution — https://mirror.codeforces.com/contest/2180/submission/354177090

  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it +6 Vote: I do not like it
    Failing testcase
    • »
      »
      »
      4 months ago, hide # ^ |
       
      Vote: I like it +3 Vote: I do not like it

      yuhh... but why tho?

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

        I have understood it intuitively like this:

        We are building the numbers from the highest bit to the lowest. The restriction that $$$a_i \lt n$$$ is annoying, but basically only matters for $$$a_i$$$'s where the bits don't match with $$$n$$$. So each time we're forced to place a $$$0$$$, we place it for $$$a_i$$$'s where the bits match with $$$n$$$ so far, this is exactly what the editorial is calling as "tight". Once $$$a_i$$$ no longer matches with $$$n$$$, we can place 1s even where $$$n$$$ has the bit as 0.

        The issue with OP's solution is the following: you're only placing the extra 0s at the last 2 numbers. The "give 1 to y and 0 to x" is the right idea, so that from now on we can add 1s to both x and y after that point, but what about the remaining $$$k-2$$$ numbers? For cases where the bit is set to 1 in $$$n$$$ but we're forced to add a 0, adding 0 to these $$$k-2$$$ numbers would be useful too. But we're fixing them as 1 in the wrong solution and always giving the 0 to y which is wasteful in a sense. It would be more useful if the 0 is given somewhere else, so that later on we can set 1 even where n is set as 0.

        Hence keeping as many numbers as loose is useful.

        Also in general, when you have a greedy strategy, your question shouldn't be "why doesn't it work". Do you have a proof, or a clear reasoning as to why it's correct? It's on the solver to prove the greedy idea. Realistically you can't formally prove ideas in a contest, but strong reasoning must be there as to why it's correct.

        Here the solution with loose and tight $$$a_i$$$'s works because it is optimal to keep as many bits set as possible when moving from MSB to LSB. If we keep a 0 where we could have kept a 1, the only gain is in the rest of the bits of that number, which is not good enough to be better than the loss we got from a higher bit. And once we follow this strategy, we also want to keep as many numbers "loose" as possible.

        This in my opinion is reasoning you can realistically come up with in a contest as to why the editorial's greedy idea is correct. (Not that it's easy to come up with this, I myself didn't lol)

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

      what would the answer be for this testcase

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

    Taking k-2 n's is not optimal,starting from MSB for each set bit give k-1 elements bit 1 and one number bit 0 at that position for the next set bit choose a different element to give bit 0 this way when we have a 0 we can choose to give even number of 1's to some of the elements in which case the sum of numbers will be larger. Basically you are only allocating two 1's (in x and y) for the unset bit in n but it is possible that more than two 1's can be allocated.

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

    i also implemented exact similar way, we are correct if k = 2, our assumption that taking k-2 n's is wrong , we just have to extend our logic for k whatever we implemented for k=2

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

    Well, I tried the same approach in the contest, and I was as confused as you about how it didn't work until someone showed me this: (I'm going to give the examples in binary so that it looks immediately correct)

    • n = 0b101101001101101101
    • k = 8
    • ans =
    • [0b001111111111111111,
    • 0b100111111111111111,
    • 0b101001111111111111,
    • 0b101100111111111111,
    • 0b101101000111111111,
    • 0b101101001011111111,
    • 0b101101001100111111,
    • 0b101101001101010010]

    I see that you tried exploiting the second 1 that you encounter in n to obtain a greater sum. That was my idea, too. But why not try to exploit the 1's as much as possible? So, lesson I learned: think a little deeper, and get a stronger reasoning.

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

    try n=6 k=4... You will get the idea.

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

    you know,the most difficult part of this problem is recognizing that take k-2 n's isn't good.

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

I wish there was a clearer explanation for Problem C. The notation in this tutorial is quite confusing—what do T = 1,…,k even mean? The definitions of T and L don’t match the explanations at all, and the reasoning doesn’t correspond to the code either.

  • »
    »
    4 months ago, hide # ^ |
    Rev. 5  
    Vote: I like it +20 Vote: I do not like it

    I tried to write down my approach to Problem C, it is a bit hard to explain in words.

    The odd case is trivial.

    For the even case, observe that in order for XOR-sum to equal $$$N$$$, at every $$$j$$$-th bit where $$$N$$$ is 1, in the answer, $$$K-1$$$ numbers must have the $$$j$$$-th bit set to 1, and one must be a 0. Let's call such bit positions 1-bits.

    For the bits where $$$N$$$ is 0, ideally we will want to set all $$$K$$$ numbers of the output to 1's, but this is not always possible because our numbers in the output might become larger than $$$N$$$.

    So, we can take advantage of the fact that at every 1-bit of $$$N$$$, we can take an opportunity to set a particular bit to 0, and from then onward this number will be strictly smaller than $$$N$$$, so further 0 bits can be turned on to maximize the sum, in these numbers. (Note that only even number of such 0 must be flipped on, though)

    Key is to choose different number each time to turn off a particular 1-bit, and not only one number, which is the trap.

    Time Complexity. $$$O(K + (log \ N)^2)$$$.

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

      you nailed it

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

        can you explain why

        (Note that only even number of such 0 must be flipped on, though)

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

          For the 0-bit positions, we want the final XOR-sum to be equal to $$$0$$$ at those positions. Thus at each such bit position in the output numbers, we should flip an even number of them (as many as we can without the numbers exceeding $$$N$$$, of course).

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

      Best explanation of solution to problem C I've seen so far. Thanks bro

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

      Amazing explanation. Thank you!

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

      instead of doing the ChatGPT they should've asked you to make the editorial, such a good explanation compared to the absolute shit of an editorial to such a good problem.

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

      good explanation! thanks!

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

I would like to share a solution for pE using the segment tree insertion function.

Similar to observations made in other solutions, we can see that for the same high-bit, if the count of 0s does not equal the count of 1s, swapping is definitely not possible. Conversely, if they are equal, swapping has no impact.

We can use a divide-and-conquer approach to maintain the counts of 0s and 1s.Specifically, if the range [l,r] covers the entire interval, the feasibility of this bit remains unaffected because the counts of 0s and 1s in this interval are identical. Therefore, we can ignore the coverage relationship—much like a segment tree. We can maintain the solution for this problem using a similar method. The code is as follows:

https://mirror.codeforces.com/contest/2180/submission/354220593

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

    Would you mind elaborating more on that part of "count of 0s not being equal to count of 1s"? I haven't found any other solutions, and since there is no editorial yet, I can't understand what is that count. What do you mean by "swapping"?

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

      I think they mean if $$$t$$$ is a valid number (i.e. we can use it), then going over each of its bits, if count of numbers from $$$l$$$ to $$$r$$$ with 0 at this bit is not equal to count to numbers with 1, then $$$t$$$ cannot have 1 at this bit because that will map numbers with 0 to numbers with 1 (at that bit). However, their number is different, so that is wrong.

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

        Oh, ok, I get it now, thanks. Now I will see if I can understand the segment tree part.

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

    That's very good insight. Great solution!

»
4 months ago, hide # |
 
Vote: I like it -22 Vote: I do not like it

According to CList, problem C was roughly a 1900 rated problem. I solved A-C and my rating only went to 1587 from 1561. Why?

»
4 months ago, hide # |
 
Vote: I like it -19 Vote: I do not like it

https://mirror.codeforces.com/problemset/problem/632/C

Task B has appeared before in edu round.

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

    That problems says that concatenation can be done in arbitrary order. In this round problem order can't be arbitrary. E.g. strings are "a", "b" and "c". You can get "acb" here.

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

      Sorry I meant , similar to this task. Because it's based on same principle. My bad.after seeing B i remembered this task.

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

Waiting for the prove of D

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

AmirrzwM Provide the proof for the greedy please, it can't be that hard that you need to omit it.

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

"the special editorial"... why is GPT content so much praised?

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

If you're like me and keep on misreading statements, you might be interested in the variation of problem F where walls have infinite length (in one direction). I believe I found a solution :

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

How to prove greedy in D?

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

    If a circle with center at i th position is connected to the circle with center at the (i + 1)th position then let it be represented by 1.

    So, A binary string will be formed of length n — 1.

    Example 0011100111

    So the string ith character is representing, if the circle at center i is connected to the circle at center i + 1.

    So our greedy statergy to start from the ith position and go untill we are able to form a

    continuous line of connected cycle.

    so let the ith character be first positon where the optimal and greedy statergy differs

    1111011(Greedy) 1110111(Optimal)

    Now since character at i + 2 depending only on the i +1 character not on ith character so we can create optimal solution starting from i + 2 character without depending on first i characters of the greedy

    Sorry for the bad explanation but hope you get the idea.

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

What's the reason for 5000 limit in problem F1? I doesn't allow to declare n*n*2*2 array and to use recursion. Declaring n * n array to precalculate powers of 4 already takes 500MB out of 512MB. So frustrating... Why N is not 1000? Idea doesn't change from it at all.

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

    I also agree that the memory limit only adds a slight difficulty to the problem that just requires you to do the queries offline, but I can that say that they probably wanted the question to be a bit harder since it is F1. Btw you should not use an $$$n^2$$$ array to precalculate the powers of 4, it is fast enough to use a $$$O(log(nm))$$$ exponential algorithm.

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

      Making the problem harder with ridiculous limits is so disgusting. There's absolutely no reason to give N=5000. Look at the solutions that didn't toggle, they use 400MB or 500MB, so just give 1024MB. This has to be the worst limit I've seen in cf after that 120^5 problem. Also for gevak, you can save 4^0~4^m, 4^(m*i) (i<=n) and make the memory smaller(Which I couldn't come up during the contest and failed to reduce the memory at 600MB)

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

        Interesting idea about memorization 4^0~4^m, 4^(m*i) (i<=n)!

        Finally managed to get AC, storing all n*n*2*2 states and all n*n powers of 4: https://mirror.codeforces.com/contest/2180/submission/354268056

        int dp[5001][5001][2][2] stores answer for all states, which takes 400MB. int pow4[5001 * 5001] stores all powers of 4, which takes 100MB.

        Thus 500MB in total. And this iterative version takes 3000ms time. Recursive version takes 6000ms, which is close, but just a bit over TL.

        Interesting problem, but very frustrating N <= 5000 limit.

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

          NICE! I still think that the technique used in the tutorial solution is intended, but if they really wanted to go that way the memory limit should be way less (like 128MB or even 64MB) instead of the normal 500MB.

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

    Probably it was a cut point for some other solution.

    I had implemented N * M * 32, which does not work.

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

    Btw, declaring an array of $$$4 n^2$$$ is possible, if you use the int type. Together with a precalculated power array, this gives $$$5 n^2 \cdot 4 \text{byte} \approx 400 \text{MB}$$$. Recursion is not a good idea anyway for $$$O(n^2)$$$ with $$$n=5000$$$. (In the end because I needed $$$6n^2$$$ space I did do space-saving style DP so I didn't need the $$$4n^2$$$ of storage). I do agree that adjusting limits to either side would have been better. Lower, such that for example $$$n^2$$$ integers does not fit, makes sure that you have to do some memory optimization. Higher, just makes sure not too many approaches are on the edge of memory limit.

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

Here is my approach for C

for odd k , just print n 'k' times

for even k ,

My idea was to try to bring in as much numbers(out of those k) in that category 'which will have 1 at the bit when n has a 0 at that bit' and as soon as possible .

starting from the highest set bit in n, let the bit be 'b': if b is 1 :
we need to have odd number of 1's (in those k numbers combined) at the b th bit , and so obviously to maximise the sum, we would want k-1 numbers to be set 1 at this bit. so make the 1st number of the list have a 0 bit here and rest all 1 bit. Next time we encounter a 1 in n , we make the second number of the list 0 here at this bit and rest all 1 . So after encountering 'k' 1's in n , we would have tried out all k numbers. Now , all the k numbers have been made < n .and in future whenever we encounter a 1 in n , doesn't matter you can make any of the k numbers 0 randomly .

And meanwhile in this process, whenever we encounter a 0 in n , we make the first 2*(num/2) numbers of the list to be 1 here. (Where num is the count of numbers which have been made < n so far) . Once num hits k , we can make all the numbers to be 1 here without violating [0,n] condition.

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

is there any proof for any of this question? it will be better if you add proof of working or something that can we proof with that the solutions.

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

To ensure no overlap, r_i + r_i+1 <= d_i. Thus, 0 < r_i+1 <= d_i — r_i. Doesn't this mean r_i < d_i (strict, for i < n)? In the editorial, it is given as a non-strict inequality so I'm confused.

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

In D, when we remove the disks from a prefix, the radius of the last center in the prefix will still affect the next set.

How do we guarantee that our choice of the radius of the first center in the second set will not cause it to overlap with the circle from the previous set?

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

    Say the ith circle is the one that wasn't able to connect to the prefix. This means that even if it had its maximum possible radius (i.e., min(x[i+1]-x[i], x[i]-x[i-1]) it couldn't reach the (i-1)th circle. This also means that any radius you choose futurely (when you start a new "prefix component" at i) won't be affected by the (i-1)th radius, because it will never happen that the ith and (i-1)th circles touch.

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

      Yeah, that's what I figured after some time. Thank you so much! Great explanation.

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

For G, you would end up with something $$$/(L-1)$$$ if you didn't realize that the sequence is palindrome. This is actually invalid when $$$L-1$$$ is a multiple of $$$10^9+7$$$. The authors seem not to have noticed this and it could pass systest in contest, but three out of five solutions in contest got hacked afterwards.

What funny is that in maroon's code, he wrote something like $$$*(L-1)/(L-1)$$$, which could have caused him some trouble if the hack existed in contest.

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

    I am wondering how the solution works without realizing it is a palindrome, can you give me a brief explanation? Thanks.

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

      The contribution for a single position $$$i$$$ (counting from backwards) is $$$2^{L-1}-i\times\frac{1+2^{L-1}(L-2)}{L(L-1)}$$$. This can be achieved by finding the pattern with brute force, or by some combinatorics calculation.

      In the end we need to maintain the length, sum of $$$a_i$$$, sum of $$$i\times a_i$$$. The difficult part is to find out which element is deleted for every operation $$$1$$$. Break the sequence into two parts from the middle. For each part, we need to insert $$$x$$$ and delete the first (or last) element.

      For every insertion operation, every $$$x$$$ inserted will be in positions $$$s,s+d,s+2d,s+3d,\cdots$$$, and a single operation either adds all $$$s$$$ by some value, or multiplies all $$$d$$$ by some value. Use a segment tree to maintain all $$$s,d$$$, and the element deleted every time is the one with minimum $$$s$$$.

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

I think E,F1,F2 and G are all standard problems with heavy implementation. What's the point of putting those problems in a 2.5h contest???

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

    I completely agree that 3h is the better choice, but let me disagree about E: it’s only 12 lines. Also, I know finding the coefficient of $$$F$$$ may be boring, but the implementation is short. Either way, $$$G$$$ does not count as a heavy-implementation Codeforces problem in my opinion.

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

      G definitely is a heavy-implementation Codeforces problem

      • »
        »
        »
        »
        4 months ago, hide # ^ |
         
        Vote: I like it -10 Vote: I do not like it

        Common, see editorial's implementation, did you count it heavy-implementation? Its implementation is more technical in my opinion.

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

        Hi Kevin! Could you share your first thoughts on Problem E? Your solution is really elegant and I'm curious about your thought process. When you first read Problem E, what was your initial intuition and what was the first thing that came to your mind when you saw the XOR operation with the constraint that all frogs must stay within the range? I'd love to know how you developed this approach of checking each bit position individually — did you start by working through small examples by hand and notice the pattern, or did you think about how XOR affects numbers at each bit level like flipping within blocks, or maybe you had some key insight that led you directly to this solution? The idea of checking whether the range is symmetric around the midpoint or covers complete blocks for each bit position is really clever, so I'm wondering how you came up with the specific conditions like r — mid == mid — l — 1 and r % i == i-1 && l % i == 0. I'm trying to improve my problem-solving skills and understanding how others go from reading a problem to finding such a clean solution would be super helpful, so thanks for sharing!

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

Editorial for E?

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

There is a mistake in the F1 editorial's DP transitions.

For dp[i][j][0][1], the coefficient for dp[i][j+1][1][1] should be 5/16 instead.

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

ok, I just realized that I didn't pass C beacause I wrote something like this:

memset(arr + 1, 0, sizeof(int) * n));

..........

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

The question yesterday was terrible. I hope I won't encounter it again in the future

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

It is super frustrated I stuck at problem C. My brain kept telling me that if k is even, just pick k-2 n, and only need to optimize the rest.

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

There is a slight typo in F1. The transition equation for $$$dp[i][j][0][1]$$$ and $$$dp[i][j][1][1]$$$ are not what is in the implemented solution. These are the fixed equations:

  • $$$dp[i][j][0][1] = \frac{3}{16}dp[i+1][j][0][0] + \frac{3}{8}dp[i+1][j][0][1] + \frac{1}{16}dp[i][j+1][1][0] + \frac{5}{16}dp[i][j+1][1][1]$$$
  • $$$dp[i][j][1][1] = \frac{1}{4}dp[i+1][j][0][0] + \frac{1}{2}dp[i+1][j][0][1] + \frac{3}{16}dp[i][j+1][1][1]$$$
»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

We are like Greece.

Persia won't stop until they invade our ratings.

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

can anyone tell what is wrong in my submisson for question C

https://mirror.codeforces.com/contest/2180/submission/354264435

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

In C, instead of maintaining 2 sets, I used mergeable treaps to maintain all numbers in sorted order and perform += on prefix

354170111

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

awesome contest!! loved it.. need more like it

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

The problem D matches a lot with https://mirror.codeforces.com/gym/106073/problem/I this problem

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

I tried solving D using a dp approach as follows:

dp[i][0] means we make a tangent pair between i and i-1

dp[i][1] means we skip this tangent pair. Although i understand why this approach is wrong, i was still thinking if this approach can be modified into a valid solution.

Anyone thinking along the same line, their help will be appreciated. Thanks

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

    see peltorator's solution. I also tried that in the contest but then realised that dp[i][1] will not be possible so you cant have that as a valid transition.

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

In problem C, I used a greedy approach that seems to require little thought. Is its correctness guaranteed?

code

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

Can somebody explain problem E?

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

In Problem D, I think it should be $$$0 \lt r_i \lt d_i$$$ instead of $$$0 \lt r_i \le d_i$$$?

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

Can someone explain the bitwise approach for E?

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

    Define $$$f(a,b,x,c,d,y,k)$$$ as when considering the low $$$k$$$ bits of $$$a,b,x,c,d,y$$$, the number of $$$t\in [0, 2^k)$$$ such that $$$\forall i\in[a,b]$$$, $$$i\oplus t\ge x$$$, and $$$\forall j\in[c,d]$$$, $$$j\oplus t\le y$$$.

    We can see the answer is exactly $$$f(l,r,l,l,r,r,60)$$$.

    Next, consider how to calculate $$$f(a,b,x,c,d,y,k)$$$, enumerating the $$$k$$$-th bit of $$$t$$$ from 0 to 1, and we can express $$$f(a,b,x,c,d,y,k)$$$ as the sum of several (possibly zero) $$$f(.,.,.,.,.,.,k-1)$$$.

    Doing this with memorized search gives a correct time complexity, as when you write out all the possible value of the parameters, you will find $$$a,x,c$$$ will either be $$$0$$$ or $$$l$$$, and $$$b,d,y$$$ will either be $$$2^{60}-1$$$ or $$$r$$$.

    Time complexity: $$$O(2^{6}\log r)$$$.

    Sample code: 354930229

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

In problem D, don't we have to use the greedy approach from left as well as right, i.e. assuming the leftmost radius a free variable first and then assuming the rightmost radius to be the free variable? The point made in the editorial that each break starts a new fresh problem is still correct though.

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

The solution of C is confusing

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

why editorials are so trash lately? Why are you skipping steps of the solution? Why are you explaining in such complex language if you can simplify it without loosing the idea?

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

can some1 explain the formula for A?

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

is F a problem?

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

Problem G is actually two completely independent problems. It can be split into two separate ones, with the first operation removed from one and the third operation removed from the other.

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

Problem D. Also, note that once we set it+1=fit+1 , there are no additional constraints on the choice of rit+1 coming from earlier indices. In particular, any restriction on rit+1 can only be imposed by it+1+1 (otherwise fit would not have been maximal by definition).

Could someone prove this??

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

i shd pack it up ong

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

trying to upsolve C but I am completely confused as to why my solution fails.

My logic: odd=> all the terms will be n

even=>all the terms but the last 2 can be n. the last two will be numbers such that their xor is n and sum is maximum(a+b=max and a^b=n)

1)I gave msb to a 2)after that if set bit is 0 then I ask if I can have that bit as 1 in a without exceeding n?? if yes then add it.

calculated b=n^a. can anyone please tell me what is wrong with my approach?? https://mirror.codeforces.com/contest/2180/submission/354513423

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

What problem with C? Short statement, intresting, but simple solution. Don't understand all hate about it.

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

In the linear algebra approach of Problem E, when discussing the case $$$2^{n-1} \le r \lt 2^n$$$, I believe that $$$l$$$ and $$$r$$$ are implicitly preprocessed by factoring out their common binary prefix (i.e., shifting the interval to the block $$$b_0$$$). This was a bit confusing to me at first glance, as the preprocessing step is not stated explicitly.

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

Can anyone explain more why the basis vectors can all be of the form 2^n-1? I don’t really get the motivation here.

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

    Proof:

    Central Idea: We want so show that if a number with msb = m works then the number with all bits on that are <=m works.

    Lets define a block as a group of consecutive numbers such that any number in the group xorred with the xorring number is also in the group. It is clear that under any working xor, the range l to r will be partitioned into blocks.

    Consider any number with an msb of m that works. Consider any block in l to r that is minimal (i.e that it is not itself containing more than one block). Note that any minimal block must be self contained in some interval that is 0 to 2^(m+1)-1 under mod 2^(m+1). We want to show that the number 2^(m+1)-1 also works for this block. Since 2^(m+1)-1 just reflects numbers about the midpoint, we just need to show that the block is centered at the midpoint.

    Now, we are going to define the coordinate of a number in the modded interval by 0 to 2^(m+1)-1 in this way. [0,2^m-1] -> [-2^m, -1] and [2^m, 2^(m+1)-1] -> [1, 2^m].

    Now let us take the time to note this Lemma of Equivalent Action. Define x' as the number with the opposite coordinate as x as defined above. Suppose that x -> x + inc when xorred with a number, then clearly x' -> x'-inc.

    Now we show that any block is centered around the midpoint. Suppose that the block is not centered. Let the left of the block be l and let the right of the block be r (this is in the new coordinate system). Suppose wlog that |r| > |l| (they can't be equal since the block is not centered). Suppose that r goes to y under the xor. Note that y to r must cross the midpoint. Then note that y' is in (since it has a positive coordinate less than r) and will go to -r (by the Lemma of Equivalent Action), so -r must be in. But that contradicts that |r| > |l|, so the block is centered. If you can't quite see this, please draw a picture.

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

    There are many basis, $$$2^n-1$$$ only is important when having one block.

    The other approach published, I think it helps a lot.

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

Shit C

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

MohammadParsaElahimanesh Problem E bitwise approach not published till now

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

In my humble opinion, there's a small mistake in the solution of G: $$$\displaystyle\sum_{k=1}^n\dfrac{\binom{n-1}{k-1}}{k}$$$ doesn't equals to $$$\dfrac{2^n}{n}$$$ but equals to $$$\dfrac{2^n-1}{n}$$$. Here's a brief proof:

Note that

$$$\dfrac{\binom{n-1}{k-1}}{k}=\dfrac{(n-1)!}{k(n-k)!(k-1)!}=\dfrac{n!}{n(n-k)!k!}=\dfrac{\binom{n}{k}}{n}$$$

therefore, we have

$$$\displaystyle\sum_{k=1}^n\dfrac{\binom{n-1}{k-1}}{k}=\dfrac{\displaystyle\sum_{k=1}^n\binom{n}{k}}{n}$$$

Binomial Theorem shows that

$$$\displaystyle\sum_{k=\mathbf{0}}^n\binom{n}{k}=2^n$$$

so

$$$\displaystyle\sum_{k=\mathbf{1}}^n\binom{n}{k}=2^n-1$$$

therefore,

$$$\displaystyle\sum_{k=1}^n\dfrac{\binom{n-1}{k-1}}{k}=\dfrac{2^n-1}{n}$$$

(apologize for my poor English)

MohammadParsaElahimanesh

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

I have a solution for G but can't figure out two corner cases. Can anyone help me?

I found the answer of question 3 is: $$$\sum\limits_{i=1}^na_i\times(i\times\frac{(n-2)\times2^{n-1}+1}{n\times(n-1)}+\frac{(n-2)\times2^{n-1}+1}{n\times(n-1)}+2^{n-1})$$$. So I only need $$$\sum a_i$$$ and $$$\sum i\times a_i$$$. If something wrong, please point it out.

Then I have coded it and got WA on test 44 and 45. My code is here: 354965006. Only the main function is useful.

I found I was hacked by some thing like this: when $$$n=k\times\bmod$$$ or $$$n=k\times\bmod+1$$$, $$$\frac1n$$$ or $$$\frac1{n-1}$$$ is undefined. (Line 1231 of the code is wrong.) How to solve these two corner cases.

UPD: ops. The problem ensure $$$n\neq k\times\bmod$$$, but still $$$\frac1{n-1}$$$ maybe undefined.

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

There is a minor mistake in the code for problem F1 - in the input for loop (the first for loop) which is for(int n, m, i = 0; i < T; i++), it should be for(int n, m, i = 0; i < t; i++).

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

Cant we solve C like this

if k is odd repeat the number k times

if k is even repeat n k-2 times then makes two numbers say x and y then where(till second bit) in n there is 0 make that bit in x and y as 1 and where is 1 make x as 1 and y as 0 for the last bit make y as 1

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

I can't get the mathematical proof or some goo intuition in E explanation with bits method that how the following mapping possibility was eliminated:

some of A->C and rest of A->A.

some of C->A and rest of C->C

B->B

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

I can't understand why "the third term is never needed" in the step5 of H1, maybe it can be proven by induction in the order of q?

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

MohammadParsaElahimanesh I found the C problem really pretty, I appreciate your effort <3

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

Alternate stupid solution for F1:

  • Notice that if we stop at cell $$$(i, j)$$$, only $$$2 \cdot (i + j)$$$ points (the ones that touch the cells on our path) determine our path, and the walls for all other points can be oriented in any of the four directions.
  • On a $$$5000 \times 5000$$$ grid, for all $$$(i, j)$$$, compute $$$f(i, j)$$$ = the number of ways to choose a path from $$$(1, 1)$$$ to $$$(i, j)$$$ and orientations for walls of the $$$2 \cdot (i + j)$$$ points touching the cells in our chosen path. This can be easily done in $$$O(5000 \cdot 5000)$$$ (it also thankfully requires only $$$3 \cdot n^2$$$ memory, the ML in this problem is terrible).
  • Compute $$$g(i, j) = \sum_{a \leq i, b \leq j} f(a, b) \cdot 4^{-2 \cdot (a + b)}$$$. This can also be easily done in $$$O(5000 \cdot 5000)$$$.
  • It's easy to see that the answer to a $$$n \times m$$$ grid is $$$g(n, m) \cdot 4 ^ {(n + 1) \cdot (m + 1)}$$$.

Code: 360970649

»
4 weeks ago, hide # |
 
Vote: I like it +13 Vote: I do not like it

$$$O(n^2)$$$ solution for F2 using Lagrange interpolation: https://mirror.codeforces.com/contest/2180/submission/368065239