Ecrade_'s blog

By Ecrade_, 18 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?
»
18 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

Ecrade_ orzzzzzzzzz!

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

  • »
    »
    18 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.

    • »
      »
      »
      18 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.

      • »
        »
        »
        »
        18 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.

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

        DIV2A SAME PARITY PROOF lets just say r>c, then after changing all of the intersection points of r and c we will be left with r'(no. of rows still left with odd no. of ones). Now since c=0 now therefore sum of 1's across each column is even-->total no. of ones is even-->total no. of ones counted row by row should also be even-->r' is even.

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

          That's a clever proof and I think it's correct, thanks for sharing! I guess that completes why max(r,c) works. Maybe I should add this, since r' is even this implies that r+c must be even for every step since r+c changes by 2 or 0 only.

    • »
      »
      »
      18 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

»
18 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

  • »
    »
    18 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

    • »
      »
      »
      18 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.

      • »
        »
        »
        »
        18 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 ^_^

        • »
          »
          »
          »
          »
          18 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

          • »
            »
            »
            »
            »
            »
            18 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

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

      Maybe Think of it this way(again I am not sure about this proof). Assuming r + c is always even(maybe you can prove it , i tried to convince myself that it was true by considering some smaller test cases). Lets say the i rows which are bad are i1 , i2 , i3 , .... ip and the columns that are bad (meaning xor == 1) are j1 , j2 , ... jq . Then , consider the rows and columns which are the same(meaning 1st row , 1st col or 2nd row , 2nd col , and so on) , so its easy to see that we will always change these intersection points to decrease r and c both by 1. Now consider other cases , after perfoming the above operations lets assume that r and c both are > 0(meaning some cols(whose rows have 0 xor) are still bad , and same for some rows(which have corr col as 0 xor). Its not hard to see that , we can chose any row and col at random and change the parity of their intersection to decrease both these row and column (Lets say row 1 is bad and column 2 is bad , then chose the element (row : 1 and col : 2) and flip it.....That way both , the row and col are fixed ..... Now perform this operation until either r = 0 or c = 0. Now what ? Now assume in this case that r > 0 ( same analogy for c > 0 as well) . So , if r > 0 and c = 0..... as previously mentioned this r is always even ( since r + c is even , and each step mentioned above we decrease both r and c by 1 , r + c got decreased by 2 , so the parity of r + c remained constant throughout our operations , hence r would always be even at this instant) , Now since c = 0 , what we can do is , chose any 2 random rows , and chose a single column(any) , and change both the bits at their intersections (lets say row 1 and row 3 are bad , now chose col : 2(random) , and change the elements (1 , 2) and (3 , 2) , This way , we clear both these rows using a single column and the column's xor doesnt change as well). Continuing this process we can see that in total we needed to change r elements in this case since we assumned r > 0 & c = 0 , but in the reverse case it would be c operations . Hence answer is max(r , c) , I hope it helps....

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

        Good idea, I agree with your proof, the idea of intersections is neat, and your idea of choosing two random bad rows and choosing a random column is excellent, the use of the parity of r+c to be able to choose two random rows was amazing. Here's an alternative proof to the part after r>0 and c=0, since r+c is always even, it can change by 2 or 0 only, choose any bad row and make it good, then this would introduce a bad column, we now have r=r-1 and c=1, since r>0 and c>0, you could flip the intersection point of one of the bad rows and the bad column again to obtain r=r-2 and c=0, this ensures that we can reduce r by 1 in every step and hence the greedy solution always exists. r=r-1 and c=1 could introduce a case where r becomes 0 and c becomes 1 in which case we might need more operations but this case will never arise because r+c is always even and hence the closest we can get is r=2 and c=0 which then becomes r=1 and c=1 which then simultaneously becomes r=0 and c=0. So, i guess it only remains to show that r+c is always even which sounds like an interesting conjecture. Thanks for the proof!

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

          Wow , The idea is on the similar thought , yet Your Way of presenting it is so impressive. The proof is crystal clear , lets wait for someone to comeup with the conjecture proof. Thanks :D

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

            You should check out abhyuday_29 's proof about that claim if you haven't already.

  • »
    »
    18 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.

    • »
      »
      »
      18 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... :( :(

    • »
      »
      »
      18 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!

    • »
      »
      »
      18 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

    • »
      »
      »
      18 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

    • »
      »
      »
      18 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?

      • »
        »
        »
        »
        18 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

    • »
      »
      »
      18 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

      • »
        »
        »
        »
        17 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.

  • »
    »
    18 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.

    • »
      »
      »
      18 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!!!!!

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

    ``````

    include <bits/stdc++.h>

    using namespace std; using ll = long long int; const ll mod = 1e9+7;

    ll exp_mod(ll base, ll exp){ if(exp == 0) return 1;

    ll tmp = exp_mod(base, exp/2);
    tmp = (tmp * tmp) % mod;
    
    if(exp & 1)
        tmp = (tmp * base) % mod;
    
    return tmp;

    }

    ll mod_Inverse(ll val ){ return exp_mod( val, mod-2); } string toBinaryString(int n) { if (n == 0) return "0";

    std::string result = "";
    while (n > 0) {
        // Check the last bit (LSB) and append '1' or '0'
        result += (n & 1) ? '1' : '0';
        n >>= 1; // Right shift by 1 bit (same as dividing by 2)
    }
    
    // Reverse the string since bits were gathered from right to left
    std::reverse(result.begin(), result.end());
    return result;

    } int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t;cin>>t;

    // vector dp(1e5+1,0); // // ll prob = mod_Inverse(2); // for(int i = 2;i<= 1e5;i++){ // dp[i] = (dp[i/2]+dp[(i+1)/2]); // dp[i] *= 0.5; // // dp[i] %=mod; // dp[i] +=1; // // dp[ i] %= mod; // } // for(int i = 1; i<= 100 ;i++){ // cout << i <<" " << dp[i] <<" " << dp[i]-dp[i-1]<<endl; while(t--){ ll n; cin>>n; string x ;cin>>x; // ll tans = pow(2,x.size()-1); ll tans = exp_mod(2,x.size()-1); // double tmp = 1.0/tans; ll tmp = mod_Inverse(tans); // cout <<tmp<<endl; reverse(x.begin(), x.end()); ll ans = (x.size()+mod-1)%mod; for(int i = 0 ; i< x.size()-1;i++){ if( x[i]=='1'){ ll pmp = exp_mod(2,i); ans += (pmp*tmp)%mod; ans%=mod; } } cout<<ans<<endl; // cout <<dp[x] <<endl; }

    return 0;

    } ```````` you can do this thing if you know how to solve dp for normal element then output values for each i and see how diffrence is constant for values and than changes after 2**x, and is1/(2**x-1) , i think this more better approach

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

  • »
    »
    18 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.

    • »
      »
      »
      18 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 ?

      • »
        »
        »
        »
        18 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.

  • »
    »
    18 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!

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

Thanks!very interesting problem

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

.

»
18 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

  • »
    »
    18 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.

»
18 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"

  • »
    »
    18 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

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

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

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

  • »
    »
    18 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.

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

»
18 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)

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

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

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

»
18 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]

  • »
    »
    18 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

»
18 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")

  • »
    »
    18 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?

  • »
    »
    18 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}$$$.

    • »
      »
      »
      18 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.

      • »
        »
        »
        »
        18 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$$$.

      • »
        »
        »
        »
        18 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}$$$.

»
18 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

  • »
    »
    18 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.

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

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

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

»
18 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://codeforces.me/contest/2082/submission/310748995

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

  • »
    »
    18 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$$$.

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

  • »
    »
    18 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.)

    • »
      »
      »
      18 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.

      • »
        »
        »
        »
        18 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$$$.

        • »
          »
          »
          »
          »
          18 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!

          • »
            »
            »
            »
            »
            »
            18 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.

            • »
              »
              »
              »
              »
              »
              »
              18 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.

              • »
                »
                »
                »
                »
                »
                »
                »
                18 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.

              • »
                »
                »
                »
                »
                »
                »
                »
                18 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.

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  18 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$$$

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

                  Thank a lot, I get it!

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  18 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$$$

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

                  I make some mistake in writing.hhhh

      • »
        »
        »
        »
        18 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.

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

  • »
    »
    18 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.

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

      then how do u deal with the two R1?

      • »
        »
        »
        »
        18 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.

        • »
          »
          »
          »
          »
          18 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.

          • »
            »
            »
            »
            »
            »
            18 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.

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

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

»
17 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

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

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

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

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

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

»
8 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
»
5 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Ecrade_

May I ask how to constructively prove, via recursion, that the condition $$$a_{p_2}-a_{p_1}\ge p_2-p_1$$$ is both necessary and sufficient?

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

    If no operation is applied to a given interval, its margin will still be bounded by intervals where $$$a_R-A_L \gt R-L$$$

    I use LLM for transformation so maybe it's bad.