Ecrade_'s blog

By Ecrade_, 13 months ago, In English

Sorry for the late editorial. Our problem setters were so exhausted with the offline competition yesterday that they really need some good rest.

Despite the unexpected and unpleasant incidents that occurred, we are truly surprised and grateful that so many of you still participated in this competition! We sincerely hope you enjoyed it!

(Gratitude for all you guys from Ecrade_: I felt so heartbroken when I heard about the unexpected issues, but seeing so many people in the comments comforting us, sharing thoughtful and positive messages that showed genuine empathy, and continuing to fully support our competition even after the wasted time, I was deeply moved. Thank you all! Codeforces truly embodies such a positive and uplifting community spirit!)

2082A - Binary Matrix
Idea: Ecrade_

Hint
Solution
Code

2082B - Floor or Ceil
Idea: Ecrade_, FairyWinx

Hint 1
Hint 2
Solution
Code

2081A - Math Division
Idea: Ecrade_

Hint 1
Hint 2
Hint 3
Solution
Code

2081B - Balancing
Idea: Ecrade_

Hint 1
Hint 2
Solution
Code

2081C - Quaternary Matrix
Idea: Ecrade_

Hint 1
Hint 2
Solution
Code

2081D - MST in Modulo Graph
Idea: newbiewzs

Hint
Solution
Code

2081E - Quantifier
Idea: chen_03

Hint 1
Hint 2
Hint 3
Hint 4
Solution
Code

2081F - Hot Matrix
Idea: 18Michael

Solution
Code

2081G1 - Hard Formula
Idea: Prean

Hint 1
Hint 2
Solution
Code

2081G2 - Hard Formula (Hard Version)
Idea: Prean

Hint 1
Hint 2
Solution
Code
  • Vote: I like it
  • +167
  • Vote: I do not like it

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

Ecrade_ orzzzzzzzzz!

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

the solution in editorial for A is fine and quite understandable but i was expecting to see a proof for the claim, i personally did find it hard to see that the answer is max(r,c), yes changing a cell implies that r and c change by 1 but i dont see how that implies that the minimum number of operations is max(r,c), is there a way to construct this optimal matrix without brute force, maybe by some clever construction?

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

    $$$\max(r,c)$$$ is the lower bound of the answer, since each time we can change $$$r$$$ and $$$c$$$ only by one.

    Greedily, if $$$r$$$ and $$$c$$$ are both greater than $$$0$$$, then we should make them both minus $$$1$$$; otherwise, let's assume that $$$r \gt 0$$$ and $$$c=0$$$, then we can only make $$$r$$$ minus $$$1$$$ and $$$c$$$ plus $$$1$$$. This greedy strategy yields the lower bound $$$\max(r,c)$$$.

    You can personally perform the strategy on some small tests like $$$r=[0,0,1,1]$$$ and $$$c=[1,1,1,1]$$$, which might be helpful to your understanding.

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

      thanks for the reply! lets say that the lower bound is max(r,c) which makes sense if we greedily reduce r and c, but you haven't proven that it is always possible to transform the matrix into a good one by performing exactly max(r,c) operations or that there always exists a greedy solution, intuitively it feels like the greedy solution shouldnt always exist because +1 is always possible but apparently it does.

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

        Maybe you can create some small tests and apply the greedy solution on them. You may get some inspiration from the process.

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

      what if $$$r=5$$$ & $$$c=0$$$ how do I make both $$$r$$$ and $$$c$$$ equal $$$0$$$

      P.S: just realised that's an impossible case as parities of $$$r$$$ and $$$c$$$ will always be same

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

div2A was not at all obvious to me. however, I guessed it because I try not to think very hard in div2A but was hoping for better intuitions and maybe a little more understanding of the matrix properties.

div2B seriously made me happy that this round was unrated LMAO, and that carry-over logic by looking at bits does make me understand the solution, thanks. .. although I got div1 this time but I tried to do it virtually for div2

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

    div2A seems very difficult to prove on paper, because the parity of the number of "bad rows" puts some constraints on the parity of the number "bad cols" which are themselves kinda tricky to prove

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

      yes I also figgured out some stuff with parity, but didn't do much thinking because div2A and you loose score for time... I was expecting mention about that in the editorial

      just mentioning what is this parity thing — basically non zero XOR means parity of count of 1s is odd.

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

        I also struggled with div2B because I don't how to write ceil division mathematically (x/y+1 [x%y!=0]). But I just changed order of operation in max and min and it worked ^_^

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

          a version of ceil division which people use ceilDiv(a,b) = (a + (b-1)) / b

          here b is 2 so.. (a+1)/2

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

            Yeah I got that :) But I was saying I was not been able to prove why my approach because I was not been able to write mathematical equation for ceil division

            proof

            BTW I have taken above proof from someone's comment

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

    There is a simpler solution for div2B.

    Let $$$s_1 s_2 \ldots s_k$$$ be the binary sequence representing floor and ceil operations.

    Claim: $$$01$$$ is larger than or equal to $$$10$$$.

    Proof:

    $$$\lceil \dfrac{\lfloor \frac{x}{2} \rfloor}{2} \rceil = \lfloor \dfrac{x+2}{4} \rfloor $$$
    $$$\lfloor \dfrac{\lceil \frac{x}{2} \rceil}{2} \rfloor = \lfloor \dfrac{x+1}{4} \rfloor $$$

    Greedily sort the sequence of operations. Implement it in 10-20 lines.

    P.s. is it just me or was the round very hard? I couldn't actually solve div2B without a hint.

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

      it was hard for me too. after a long time struggled so much with B.

      C was also some expectation + dp which I am weak at... :( :(

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

      Wow that's definitely an elegant proof! Thank you for sharing it!

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

      ok, this explanation for div2B is so cool, thanks for sharing this.

      now I feel more dumb

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

      Fill in the detailed reasoning steps:

      $$$ Operation 1 : \lceil \frac{\lfloor \frac{x}{2} \rfloor}{2} \rceil = \lfloor \frac{\lfloor \frac{x}{2} \rfloor + 1}{2} \rfloor = \lfloor \frac{\lfloor \frac{x + 2}{2} \rfloor }{2} \rfloor = \lfloor \frac{x + 2}{4} \rfloor $$$
      $$$ Operation 2 : \lfloor \frac{\lceil \frac{x}{2} \rceil}{2} \rfloor = \lfloor \frac{\lfloor \frac{x + 1}{2} \rfloor}{2} \rfloor = \lfloor \frac{x + 1}{4} \rfloor $$$

      Obviously,operation 1 is no worse than operation 2

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

      can't we do 11? which gives floor( (x + 3 ) / 4 ). which is bigger. how this proves 000....11 is better for max?

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

        First, let's define two operator functions:

        $$$ f(x) := \lfloor \frac{x}{2} \rfloor, g(x) := \lceil \frac{x}{2} \rceil $$$

        Then, the cases of applying the function f first and applying the function g first are as follows:

        $$$ g(f(x)) = \lceil \frac{\lfloor \frac{x}{2} \rfloor}{2} \rceil = \lfloor \frac{\lfloor \frac{x}{2} \rfloor + 1}{2} \rfloor = \lfloor \frac{\lfloor \frac{x + 2}{2} \rfloor }{2} \rfloor = \lfloor \frac{x + 2}{4} \rfloor $$$
        $$$ f(g(x)) = \lfloor \frac{\lceil \frac{x}{2} \rceil}{2} \rfloor = \lfloor \frac{\lfloor \frac{x + 1}{2} \rfloor }{2} \rfloor = \lfloor \frac{x + 1}{4} \rfloor $$$

        When there are too many operations the notation of the compound function is too long to be easily observed, let's simplify the notation:

        $$$ fgff... := f(g(f(f...(x)...))) $$$

        For any sequence of operations (e.g., $$$fgffgggfgf...$$$), for two adjacent terms , we can replace $$$fg$$$ with $$$gf$$$ and the answer will not be worse, so the optimal sequence of operations must be of the form $$$ggggggfffffff... $$$

        P.s. In fact, the above proof technique is often used in greedy algorithms and is known as the inductive exchange argument

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

      Hello I actually went through your submissions for this problem and had the same logic that if x is odd we do ceil for max and floor for min value and if even we do the opposite but it gave TLE due to large m and n so i limited m/n to 30 but still it gives wrong answer can you tell me why because the correct answer just does floor first then ceil for max. Your help would be really appreciated

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

        This might be because of applying ceil operation when x reaches 1, applying ceil on x = 1 will not change x and you applying the loop until x reaches zero or number of opearations become zero.

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

    The intended solutions of these two problems are very simple and not that hard to guess, and guessing some conclusions is, to some extent, an important skill in programming contests, as you only need to write the code instead of the proof.

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

      yes I am lowkey happy that I saw some tough problem, shows me I need to grind harder. and editorial of B is also very helpful ,thanks for that ... instead of just saying "it is trival to show" LMAO

      but why won't these tears stop .... aaaaaaa!!!!!

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

div2C/div1A: it is noteworthy that a closed form solution exists (that can be derived from the recurrence relation):

$$$E(x) = x/2^{n-1} + n - 2$$$
»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can someone explain the recurrence relation mentioned in Div2 C or Div 1 A Math Division problem?

if the i'th least significant bit is 1, why is it 1/2 * (1 — f(i-1)) + f(i-1)?

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

    Assume that the current bit is $$$1$$$. If a carry-over occurs in the previous bit (with probability $$$f_{i-1}$$$), then a carry-over always occurs in the current bit; otherwise, if a carry-over doesn't occur in the previous bit (with probability $$$1-f_{i-1}$$$), then a carry-over occurs in the current bit only when we perform the ceil operation.

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

      Ecrade_ why we are particularly focussing on n-1th step having a carry over or not ?as such it might happen that carry over happened in some steps before which leads to same n steps answer.

      like for example consider s="11111" , here we can get 5 steps answer by doing a ceil in any of the steps. so why particularly in 5th step we want a carry over only ?

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

        When a carry-over occurs on a bit, we temporarily store it on the next bit and should not let it affect other bits.

        For example, s = "11111", if we do ceil operation first, s will become "1112" instead of "10000". And if we do floor operation next, s will become "112", since a carry-over always occurs on a "2" bit, etc.

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

    http://bit.ly/4bUiAmK

    https://bit.ly/4bXo8gh

    These are the basic proofs on how to derive the recurrence relation and closed form solution.I solved using the formula i derived.You can also check my submission here:- 310940670 This problem was really fun to solve ! liked it alot !

    Hope this helps!

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

Thanks!very interesting problem

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

.

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

You can also turn off your brain in Div1-A and just calculate the probability of which bit is in position and whether there is a transition through the digit

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

    It feels like I'm a clown after reading how simple the editorial solution is for D1A-D2C (vs my solution — the turn off brain one).

    Oh well, Today I learn.

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

Can someone please explain solution for problem B. I am not able to understand :( what is meant by this term "carry over"

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

    it just means that can a 1 survive after the operation

    so you can carry over 1 towards right with ceil, but you can't do it with floor.

    to get max value we want to carry over, for min we don't want to carry over

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

Proud of my solution -> read editorial -> cry.

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

can someone tell me why does the following approach fail for div2B?

  1. to reach the minimal value, we use the type 2 operation whenever x is even, and type 1 operation otherwise.
  2. if any of the operations is exhausted, we terminate the above step and apply the remaining operations until x becomes 0 or 1 or until all the operations of both types are exhausted.

we repeat the same steps to find maximal value but with just one change, we use type 2 operation when x is odd and type 1 operation otherwise.

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

    At first my idea is that too, but turns out that it's not. And yeah, it's hard to see that why it's wrong. Consider the test case:

    1

    11 1 2

    The problem with that greedy idea is that, sometimes, “burning” straight away a type 1 operation could lead to “burning” one of your floor operations when it would be more beneficial to delay it. In this test case:

    • If you use Type 1 first (since it's odd), then you are left with 5. But when you must do two other Type 2 operations, it becomes 3 and 2.

    • But the optimal solution should be you use two Type 2 operations first, which leads to 6 and 3. Then, if you do a Type 1, you will yield the minimum value which is 1, not 2.

    I think most of the people thought about the "even/odd" greedy idea, and it certainly is hard to know why it's wrong.

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

I might be mistaken, but shouldn't $$$l$$$ in Div1B/Div2D be ceil instead of floor?

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

B was really cool. I originally thought that having to save floors for the end to reach 0 when finding min was an edge case but after thinking about binary it makes way more sense. To find the min you use ceil because ceil stacks / carries over all the 1's in the binary representation of the number and moves them left. This allows you to minimize the number of ones and have a better chance of using the floors to cut off all the 1's and make the number 0. Conversely, for max you want to keep as many 1's as possible so the floor won't be able to get to 0 and the max will be as big as possible. Great problem despite the technical difficulties, thanks for the round!

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

    What does ceil carry over all the 1s in the binary representation to the left mean?

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

thanks for the contest Ecrade_

Div1 B, C, D, E are all good problems I think. (cant comment about F and G felt not that since especially since hardcoding solutions exist)

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

in Div1B why cant it be the case that instead of first and last elements we choose some other pair whose values have been changed. Why is it only valid if we can do the first and last element in the end.

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

There also exists a $$$O(n\log^2n)$$$ solution in Div1 D using the Boruvka algorithm. It's much more difficult to implement than the official editorial, but sadly without any brain I can't notice the key observasion :(

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

I usually like going through the editorials just to scan how complex the solutions look for thr hardest problems and my god have I not seen such a scary looking solution in a long time like problem G.

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

In Div2C can you explain further why the expected operations is n-1 + f[n-1]?

In my understanding, x will become 1 after n or n-1 operations. So the expected operations is: n*p[n] + (n-1)*p[n-1]

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

    sorry idk how to format maths but here we go :

    E(x) = n-1 * prob(n-1) + n *(prob(n))

    according to the problem no of moves are n-1 when no carry over occures at n-1th pos , if it does occure then no of moves are n

    -> E(x) = n-1 * (prob of carry over not happening) + n * (prob of carry over at n-1th pos )

    -> E(x) = n-1 * (1 — prob(carry-over at n-1)) + n * (prob(carry-over at n-1)
    -> E(x) = n — n *p(cv) — 1 + prob(cv) + n*p(cv)
    -> E(x) = n-1 + prob(cv)
    i hope it helps

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

Prean Is the time complexity for G1 correct? Isn't the runtime of computing $$$S(1,1)$$$ actually near-linear ($$$\omega(n^{1-\epsilon})$$$ for any $$$\epsilon \gt 0$$$), according to this?

https://baihacker.github.io/main/2020/The_prefix-sum_of_multiplicative_function_the_black_algorithm.html

(Section: "The black algorithm — complexity")

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

    Also, I wonder what the time complexity of "DFS Code" in G2 actually is — if I'm understanding it correctly, it is the same as the DFS in G1 except with the additional "return true," but does it provably improve the time complexity?

    P.S.: what is Du Sieve?

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

    https://zhuanlan.zhihu.com/p/33544708。 Here proves that $$$\min25$$$ could run in $$$O(\frac{n^{\frac 34}}{\log n})$$$ when $$$n\le 10^{12}$$$.

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

      An issue is that it looks people call different things as "min25" (and it is probably often even different from what Min_25 posted on their blog).

      In my understanding the exhaustive DFS is near-linear as Benq said ($$$\omega(N^{1-\epsilon})$$$ for any $$$\epsilon \gt 0$$$), and $$$o(N)$$$ at the same time. More precisely, the set $$$\{ n/\mathrm{gpf}(n) \mid 2 \le n \le N \}$$$ ($$$\mathrm{gpf}$$$ for greatest prime factor) has such size. I haven't proven this myself, but sources are:

      My in-contest submission does the exhaustive DFS, thus having time complexity $$$\omega(N^{1-\epsilon})$$$. Maybe asymptotic behavior is not that important in this kind of problem, we can count the actual number of states for the worst case.

      run in $$$O(\frac{n^{\frac{3}{4}}}{\log n})$$$ when $$$n \le 10^{12}$$$

      I believe this is a useless claim, because it runs in $$$O(1)$$$ time if we assume $$$n \le 10^{12}$$$ (do you know what $$$O$$$ means). You probably meant the size is practically approximated by the value $$$\frac{n^{\frac{3}{4}}}{\log n}$$$ ?

      When people say "min25 is $$$O(N^{3/4} / \log(N))$$$", I guess it might mean (1) that they don't know what $$$O$$$ means, and/or (2) that their algorithm has some improvement by DP/memoization rather than the simple DFS.

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

        Actually we have no idea about how the constraint of $$$g'(d)\neq g'(fa_d)$$$ reduce the time complexity, and it's only an empirical conclusion that it significantly reduce the order of $$$D$$$ from the normal $$$\text{Min_25}$$$ times complexity. And I apologize for my misuse of mark $$$O$$$.

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

        Additionally, the $$$\text{Min_25}$$$ we talk about is from the IOI2018 Chinese National Candidate Team Paper(page 92,Zhu Zhenting), with his proof of time complexity of $$$\text{Min_25}$$$.

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

Can someone tell me on problem div2A if r=1 and c=0 than if we reduce r than C will increase means now r=0 and c=1 so it will run forever. So how does ans = max(r,c) help

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

    It can be proven that r+c is always even, as the parity of r and c are both equal to the parity of 1s in the matrix. Try some small tests, and you’ll get some inspiration.

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

For the test case in div2D:

7
1 9 1 17 16 15 14

Why isn't the answer 3? Or if the answer is 2, how can we make it a strictly increasing sequence?

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

div2F/div1D is identical with [COCI 2016/2017 #6] Sirni.

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

I did C with different approach(dont know if it somehow is similar to the discussed above)

number of operations that can be performed are n or n-1 let n1 be total number of series with n operations. let n2 be total number of series with n-1 operations.

now total number of series that can be formed for any number x will be x only (for eg. total number of series for 6 is 6 only, for 11 it will be 11)

and n1+n2=x

and now I observed that we an find value of n1 by summing up value of 2^k from lsb and instead of k starting from 0 we will make it start with 1 and will ignore msb. for eg for 110(which is 6) I will start from lsb to msb-1 so n1 = (0*2^1)+(1*2^2) --> n1 = 4 and we can see n1 is 4 and hence we will get n2 which is x-n1.

now when we have n1 and n2 with everything done taking mod ofc.

we can now have our ans using formula (n1*n/2^n)+(n2*(n-1)/2^(n-1)) and its mod.

I am not so experienced sorry for any mistakes and tell me if I am wrong at anything. thank you

here is my solution link https://mirror.codeforces.com/contest/2082/submission/310748995

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

Div2D editorial:

Case 2: s=0 or 2∤s It's not difficult to prove that the answer in this case is l. (Why?)

Come on, if it isn't difficult, why do we need editorials? Can someone explain the solution properly?

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

    If $$$s=0$$$, then the answer is $$$l=0$$$.

    Otherwise, if $$$s \gt 0$$$ and $$$2\nmid s$$$, then if we want to obtain the lower bound $$$l$$$, we should eliminate one inversion pair in exactly one operation (call it OPER X), and two in other operations. Note that after OPER X, the condition will turn into case 1 where we obtain the lower bound only when the difference between $$$a_{p_2}$$$ and $$$a_{p_1}$$$ is large enough. We can do OPER X first, take advantage of it and make the difference between $$$a_{p_2}$$$ and $$$a_{p_1}$$$ as large as possible. Thus, we can always obtain the lower bound when $$$2\nmid s$$$.

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

In 2081B solution, it is not difficult to constructively prove by recursion that this condition is both necessary and sufficient.

How can I construct recursively? I think on the sample 1 9 1 9 8 1 0. The first operation can be 1 9 1 9 8 1 100, if I use the same principle, the first element is 1 and the end element is also 1 and the operation should be 1 9 1 9 8 99 100? In this situation, it won't be done in 3 operation. The correct operation may be 1 9 1 9 20 30 100. How can I construct the prove?

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

    I don't quite get your words. The sample 1,9,1,9,8,1,0 does not satisfy the condition $$$a_{p_2}-a_{p_1}\ge p_2-p_1$$$, and what can be proven by recursion is, when the array satisfies $$$a_{p_2}-a_{p_1}\ge p_2-p_1$$$, we can always eliminate two inversion pairs in each operation. (In other words, if $$$a_{p_2}-a_{p_1}\ge p_2-p_1$$$ is satisfied, we can always find an operation which: 1. eliminates two inversion pairs. 2. the array after the operation also satisfies the condition, which guarantees that the recursion goes on.)

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

      OK, I mean that 1,9,1,9,8,1,0 does not satisfy the condition, so that I can use one operation modify to 1 9 1 9 8 1 100, and then I can't use the same rule to get the answer.

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

        The number of inversion pairs in 1,9,1,9,8,1,100 is $$$3$$$, so it should be considered as Case 2. I've written a brief proof of Case 2 in the comments:

        If $$$s=0$$$, then the answer is $$$l=0$$$.

        Otherwise, if $$$s \gt 0$$$ and $$$2\nmid s$$$, then if we want to obtain the lower bound $$$l$$$, we should eliminate one inversion pair in exactly one operation (call it OPER X), and two in other operations. Note that after OPER X, the condition will turn into case 1 where we obtain the lower bound only when the difference between $$$a_{p_2}$$$ and $$$a_{p_1}$$$ is large enough. We can do OPER X first, take advantage of it and make the difference between $$$a_{p_2}$$$ and $$$a_{p_1}$$$ as large as possible. Thus, we can always obtain the lower bound when $$$2\nmid s$$$.

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

          Does that mean the OPER X change a pair of number? I thought that OPER X changed only one number before. I may get it now!

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

            We don't care about how many numbers we change. We only care about how many inversion pairs we eliminate.

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

              In the previous sample, if 1,9,1,9,8,1,100 change to 1,9,1,9,8,99,100, the inversion pairs is 2, but it can't be done in one operation and if change to 1,9,1,9,90,88,100, the inversion pairs is 2, and it can be done in one operation.

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

                In OPER X, we should make the difference between $$$a_{p_2}$$$ and $$$a_{p_1}$$$ as large as possible, because after OPER X, the array will turn into case 1 again.

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

                If you turn 1,9,1,9,8,1,100 into 1,9,1,9,8,99,100, then $$$p_1=2,p_2=5$$$, but $$$a_{p_2}-a_{p_1} \lt p_2-p_1$$$, so this kind of OPER X is apparently not optimal.

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

                  Oh,that means after OPER X the array should satisfy $$$a_{p2}-a_{p1} \leq p_2 - p_1$$$

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

                  Thank a lot, I get it!

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

                  *$$$a_{p_2}-a_{p_1}\ge p_2-p_1$$$

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

                  I make some mistake in writing.hhhh

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

        In other words, if the array has even number of inversion pairs and does not satisfy the condition, we can first eliminate one inversion pair, turn it to Case 2, and obtain $$$l+1$$$ number of operations.

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

In problem 1C, why can group (R1,R1,R1,C1) be decomposed to at least one P2?

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

    (R1,R1,R1,C1) -> (R1,C1)

    If a subset of a group (xor sum = 0) also forms a group (xor sum = 0), it's always optimal to decompose it, since fewer numbers are used.

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

      then how do u deal with the two R1?

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

        The conclusions are just used to prove the final strategy: first form as many $$$P_2$$$ groups as possible; then form as many $$$P_3$$$ groups as possible from the remaining elements; then form as many $$$P_4$$$ groups as possible from the remaining elements.

        Also, the proof you mentioned is just used to illustrate that there exists an optimal solution where all groups are of form $$$P_2$$$, $$$P_3$$$, $$$P_4$$$. You don't have to consider how to deal with the two $R_1$s.

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

          so u just leave behind those unable to group with others? it makes sense.

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

            The basic logic of the proof is exchange argument. You can always transform messy things into orderly things without worsening the answer.

»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
first time ...I wrote a greedy solution for B and get WA .. after that I wrote dp solution and get AC ..

MY Submission....

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

I implemented the same solution described in G1 and it passed G2 as well.

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

1C has an alternative greedy solution that I believe is easier to come up with. Not seeing any mention of this so I decide to write it down.

Consider the relaxed problem: $$$a_{ij} \in 0,1$$$. Then obviously the solution would be max(count of bad rows, count of bad columns), where we define bad rows as rows whose xor > 0.

Now consider another problem. $$$a_{ij} \in 0,1,2,3$$$, but we let the operation "x^=3" cost 2 instead of 1 (x^=1 and x^=2 still cost 1). Now the problem can be solved as 2 subproblems, one for 0,1 and one for 2,3, because the 2 bits are completely independent now.

Therefore, once we fix the $$$i,j$$$ where we perform "x^=3", the problem is solved. It turns out that such i,j can be chosen greedily. The general idea is to choose $$$i,j$$$ that reduces the final result (assuming this is the last "x^=3" operation).

More formally, define $$$f_0$$$ as max(count of bad rows, count of bad cols) for bit 0. Here count of bad rows are rows whose 0-th bit of xor is set, i.e. rows whose xor is an odd number. Similarly define $$$f_1$$$ for bit 1. The final answer = number of "x^=3" operations + $$$f_0$$$ + $$$f_1$$$ (after performing the operations).

Using $$$f_0$$$ as an example, we can make the following observation:

  1. If count of bad rows >= count of bad cols + 2, then choosing an $$$i,j$$$ where row i is bad will reduce $$$f_0$$$ by 1, regardless of whether col j is bad or not.

  2. Similarly for count of bad cols >= count of bad rows + 2.

  3. Finally, if count of bad rows == count of bad cols, then we have to choose $$$i,j$$$ where both row i and col j are bad to reduce $$$f_0$$$ by 1.

Note that $$$f_0$$$ can only be reduced by at most 1 in 1 "x^=3" operation, and the operation itself costs 1. Therefore, for an operation to be worth it, it must reduce both $$$f_0$$$ and $$$f_1$$$ by 1.

The implementation is just maintaining the xor value of rows and columns and picking $$$i,j$$$ until no operation can reduce both $$$f_0$$$ and $$$f_1$$$ by 1.

code

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

Ok for Div 1 B — I figured it out after trying multiple test-cases — but it would be very helpful if in editorial — detailed proof was available that why if 's' is even and we have sufficient numbers to put in [l,r] -> a[r] — a[l] >= l — r -> then how do we guarantee that all the even number of inversion pairs in the middle range[l+1...r-1] will also get handled if dealt with correctly — what happens with the middle inversion pairs and how to deal with them is unknown. 1 way to figure it out was trying and many test-cases by hand and seeing the pattern but is their any formal mathematical proof for same? Thanks.

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

Different proof from my side for div2A , since flipping one bit affects the xor of both row and columns thus if we have r rows and c columns which are not good then suppose r>=c ( similar can be done for c>r) so now we can make xor of c columns and c rows good and now c columns are fixed , r-c rows are left which are not good , also r and c must be of same parity since ∑(row XOR)=XOR of all matrix bits counted row-wise=all columns∑(column XOR) thus r-c must be even parity hence we can chose any one column to fix the r-c rows also since r-c is even it will not affect parity of that column hence answer will be r+r-c or in general answer is min(r,c)+abs|r-c|

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

LOL I did $$$O((logN)^3 * T)$$$ dp in $$$div2B$$$

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

what are constructive algorithms

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

I think this is the wrong tutorial? https://mirror.codeforces.com/contest/2081/problem/a

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

.

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

I have a slightly different solution than Editorial one for D2C/D1A, which is based on COUNTING WAYS.

POINT-1
POINT-2
POINT-3
POINT-4
POINT-5
POINT-6
DP Code