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

Автор dario2994, 4 года назад, По-английски

General comments

Broadly speaking, problems A-B-C-D were "div2 problems", while F-G-H were "strong grandmaster problems" (with E staying in the middle). I did not expect anyone to solve all the problems and thus I decided to give the scoring F+G=H (so that maybe someone would have solved H).

Many of the problems (A, C, D, E, G) admit multiple solutions. Sometimes the core of the solution is the same (C, D) and sometimes the solutions are truly different (A, E, G).

If you are an experienced participant, I would like to hear your opinion on the problems. Feel free to comment on this post or send me a private message.

Overview of the problemset

Hints

A

B

C

D

E

F

G

H

Solutions

A

Tutorial is loading...
Solution code
B

C

D

E

F

G

H
Разбор задач Codeforces Global Round 11
  • Проголосовать: нравится
  • +758
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится +55 Проголосовать: не нравится

Awesome editorial and even awesome questions. After this round, I feel like practicing more now.

»
4 года назад, # |
  Проголосовать: нравится +82 Проголосовать: не нравится

I really liked this contest. All problems between A and E are well-balanced. They are not almost ad-hoc, and they are not stupid realization. Ideal balance! Thanks for this round!

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +106 Проголосовать: не нравится

    But i must to say, that in my opinion it is makes no sense to do score distribution like 500-750-1000-1000-1500

»
4 года назад, # |
  Проголосовать: нравится -9 Проголосовать: не нравится

thanks for blazing fast editorial. Loved the problems <3

»
4 года назад, # |
Rev. 2   Проголосовать: нравится +15 Проголосовать: не нравится

For problem C This is a classical dynamic-programming task with a twist. Which task does this refer to?

  • »
    »
    4 года назад, # ^ |
    Rev. 2   Проголосовать: нравится +10 Проголосовать: не нравится

    It's quite similar to the longest increasing subsequence, but the condition to pick the previous element is $$$dist(i, j) \leq t_j - t_i$$$ instead of $$$a_j > a_i$$$.

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

      There is the use of upper_bound in the regular longest increasing subsequence problem of O(nlog(n)). But in this problem how I make a binary search. (dist(i,j)≤tj−ti) can give only true or false, not greater than or less than. Actually, I can't be sure my temp array will be sorted.

      • »
        »
        »
        »
        4 года назад, # ^ |
          Проголосовать: нравится +6 Проголосовать: не нравится

        The "twist" is not binary search: it's that $$$t_j - t_i \geq j - i$$$ and $$$dist(i, j) \leq 2r$$$, hence the condition is true for each $$$i, j$$$ such that $$$j - i \geq 2r$$$.

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

          Oh, thanks. Got it :)

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

            TheScrasse PrantaSaha Can someone please explain what 2*r means? The idea is that if |k−i| is big, then i and k are always compatible. More precisely, if k−i ≥ 2r then tk−ti ≥ 2r How can we be so sure about this?

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

              Since the side of the grid is $$$r$$$, the distance of the farthest vertices (two opposite corners) is $$$2r - 2$$$.

      • »
        »
        »
        »
        4 года назад, # ^ |
          Проголосовать: нравится +4 Проголосовать: не нравится

        After reading your comment a was able to understand editorial Thanks

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

    I think the task is Longest increasing subsequence:- https://www.geeksforgeeks.org/longest-increasing-subsequence-dp-3/

»
4 года назад, # |
  Проголосовать: нравится +60 Проголосовать: не нравится

it fits easily in the time-limit. it doesn't...

  • »
    »
    4 года назад, # ^ |
    Rev. 2   Проголосовать: нравится +34 Проголосовать: не нравится

    I have quickly checked your last submission during the contest, it seems to me that it is $$$O(n^4)$$$ (you are calling janusz.dinic() $$$O(n)$$$ times). If I am wrong (which is very likely), sorry.

    If you implemented the first solution in the editorial in $$$O(n^3)$$$ and you got time-limit-exceeded, I am sorry, that was of course not intended.

    Since I am here, let me comment a bit more on the time-limit of problem G. I have the feeling that in many flow problems, the general mentality is "let's ignore complexity because any flow implementation will work". In this problem this was not true. A nontrivial amount of contestants got TLE because of this. Before the contest I thought a lot about this time-limit, because I knew it would have generated quite a bit of struggling. The fundamental reason why I decided to keep it as it is, was to avoid $$$O(n^4)$$$ solutions passing and to award contestants that instead of using fancy (but with bad complexity/terrible constants) implementations of the flow algorithm were implementing the good old Ford-Fulkerson (proving its complexity!). It might be that this choice generated more suffering than joy... but as always it is much easier to judge a posteriori.

    • »
      »
      »
      4 года назад, # ^ |
      Rev. 2   Проголосовать: нравится +25 Проголосовать: не нравится

      I run dinic() $$$n$$$ times, but in total, I'll push only $$$O(n)$$$ units of flow (I'm using the network from the previous iteration).

      After the contest, I've changed Dinic to work like Ford-Fulkerson, so it doesn't run bfs. It was a bit faster, which was enough.

      • »
        »
        »
        »
        4 года назад, # ^ |
          Проголосовать: нравится +35 Проголосовать: не нравится

        That is unfortunate and it is my fault. Hopefully next time I will not make the same mistake.

»
4 года назад, # |
  Проголосовать: нравится +15 Проголосовать: не нравится

Anyone wasted an hour in B?

»
4 года назад, # |
  Проголосовать: нравится -179 Проголосовать: не нравится

In parallel universe.

»
4 года назад, # |
Rev. 2   Проголосовать: нравится +26 Проголосовать: не нравится

If $$$a=b+1$$$ and $$$b$$$ is even, then $$$a^b=1$$$.

In Hint $$$4$$$ of the first solution of problem $$$E$$$, maybe it should be $$$a\oplus b=1$$$($$$\oplus$$$ denotes xor)...

Also in Hint $$$3$$$ of the second solution, it should be $$$2^{19}$$$ but not $$$2^19$$$.

»
4 года назад, # |
Rev. 4   Проголосовать: нравится +2 Проголосовать: не нравится

Many of them could have got ac on D if it were 2*n steps,lol. By the way,thanks for a great contest.Liked it. Thanks for strong pretests

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

Me :Could only solve one, feeling low...

Also Me : After reading the overview of problemset...I am glad I solved A.

»
4 года назад, # |
  Проголосовать: нравится +59 Проголосовать: не нравится

This is peak editorial writing. From giving some extra time to the ones who were really close to getting AC on H to writing multiple hints for us to be able to figure out the rest of the solution by ourselves. Great work dude!

  • »
    »
    4 года назад, # ^ |
    Rev. 2   Проголосовать: нравится +11 Проголосовать: не нравится

    I love that, I was close to getting C and only read the hints and was able to solve it. A good way to learn is by using hints instead of revealing the whole solution.

»
4 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

Thanks for the awesome Tutorial keep it with hints its such a good way of learning and explanation :D !

»
4 года назад, # |
  Проголосовать: нравится +7 Проголосовать: не нравится

The way of presentation of the Editorial is very Nice. Going through the Hints before The Actual Solution really helps in learning. I request all editorial should be posted like this (Hints and Then solution).

»
4 года назад, # |
  Проголосовать: нравится -11 Проголосовать: не нравится

I have lost more than 200 rating points in the last 3 contests, Don't really know what's happening :/

»
4 года назад, # |
  Проголосовать: нравится +7 Проголосовать: не нравится

Great format for the editorial! Loved the bunch of hints before the elaborated solution. Thank you!

»
4 года назад, # |
  Проголосовать: нравится +10 Проголосовать: не нравится

it would have been better , if the editorials were given with the problems in the contest.

»
4 года назад, # |
  Проголосовать: нравится +48 Проголосовать: не нравится

Here are video solutions for A-E, as well as complaining about gaining rating (apparently)

»
4 года назад, # |
  Проголосовать: нравится -10 Проголосовать: не нравится

sorry for such a silly question but why am i getting TLE here? 95114705 I tried to form all possible permutations coz the constraints were very small. But still i got TLE. If anyone got time a slight help would be great. Thank you. Have a good day

»
4 года назад, # |
Rev. 2   Проголосовать: нравится -29 Проголосовать: не нравится

Can anyone tell why my solution is incorrect for Problem — B ( Chess Cheater )? My approach :

Step 0: Find the initial score and store it in variable sum
Step 1: Find all contiguous Loss substrings and store 
        (length,0) if the substring is not a prefix/suffix 
        (length,1) if it is a suffix/prefix
Step 2: Sort the vector in increasing order, putting prefix and suffix substrings at the end
Step 3: iterate for elements in the sorted vector ( for i=0;i < it.size(); i++ )
        if( k >= it[i]) // meaning we can change the whole interval 
            sum += 2*it[i] +1 if the i'th substring of L's is not a suffix or prefix
            sum += 2* it[i] if i'th substring of L's is a prefix/suffix
            k -= it[i]
        else if( k < it[i] ) // this is the last substring we can change, and we can't change it fully
            sum += 2*k 
            k=0;
Step 5: cout<< sum <<" \n" 

Link to submission : Can anyone point out the mistake kindly? Thanks in advance :)

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

    I had the same solution in contest. Consider the case

    2 0

    WW

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

    Step 2: Sort, ..., putting prefix and suffix substrings at the end

    However, this isn't what happens in the code — you sort by length first, then consider the type.

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

      Yeah, I just figured it out after posting the comment :'3 Thanks for the prompt reply anyway. I guess sometimes we rookies just lost, tearing out hair over trivial mistakes which then builds frustration and tosses the self confidence into a black hole temporarily!

»
4 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

C was much harder than D for me.

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

    Depends. If someone has good DP knowledge, C was way more easier than D and less time consuming. I took like one hour and half in D which I was too late to solve in contest so I solved it and AC after contest.

»
4 года назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

Nice editorial! It would be great if we can have hint on all the future editorials! (but that would be time consuming for the writer)

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +33 Проголосовать: не нравится

    I am glad that the hints were so appreciated. I have just followed a suggestion by Errichto.

    In any case, writing hints requires way less effort and time than writing the editorial. So, I would advise any problemsetter who has some spare time before the contest (or also during the contest!) to write hints.

»
4 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Great Set of questions. Even the editorial in this format is very informative and help in logic building.

»
4 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

This is the toughest round for me so far.

»
4 года назад, # |
Rev. 2   Проголосовать: нравится +104 Проголосовать: не нравится

There is an elementary solution to E which does not use Bezout's Theorem.

First idea of the solution
First step of the solution
Completing the solution
»
4 года назад, # |
  Проголосовать: нравится -52 Проголосовать: не нравится

For B, I used the idea of finding the contiguous substring with maximum consecutive Ws by performing at most k flips(where a flip is from W to L, L to W). Then I would calculate the winning score. I am getting the wrong answer on pretest2. Can somebody help me find out what's wrong with my solution?

Here is my code — void solve() { cin >> n >> k;

string s;
cin >> s;

vi A(n);
fo(i,n){
    if(s[i]=='W')
        A[i] = 1;
    else if(s[i]=='L')
        A[i] = 0;
}

// Now I find the contiguous substring with maximum consecutive 1s by doing at most k flips.
int l=0, r=0, maxLen=INT_MIN, maxL, maxR, c=k;
for(r=0,l=0; r<n; r++){
    if(c<0){
        while(l<=r){
            if(c>=0)
                break;
            if(A[l]==0)
                c++;
            l++;
        }
    }
    else{
        if(A[r]==0){
            c--;
            if(c<0){
                r--;
                continue;
            }
        }
        if((r-l+1)>maxLen){
            maxLen=r-l+1;
            maxL=l;
            maxR=r;
        }
    }
}

int ans = 0, j = maxL;
if(maxLen!=INT_MIN){
    while(j<=maxR){
        A[j] = 1;
        j++;
    }
    fo(i,n){
        if(i==0){
            if(A[i]==1)
                ans++;
        }
        else if(i>0 && A[i]==1){
            if(A[i-1]==1)
                ans+=2;
            else
                ans++;
        }
    }
}  

cout << ans << endl;

}

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

    Note that the solution might not be to create a single substring: consider the input

    1
    9 2
    WLWLLLWLW
    
»
4 года назад, # |
  Проголосовать: нравится +96 Проголосовать: не нравится

hence I will leave them a couple more hours to try getting AC

https://codeforces.net/contest/1427/submission/95152627

It turns out my problem was that I was simply losing too much precision when considering escaping through a very close point :(

Knowing that my answer is actually bigger than the correct one was enough to find the issue immediately.

Thanks for the contest!

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +19 Проголосовать: не нравится

    Congratulations!

    By the way, I had exactly the same bug when preparing the problem. I lost a full day on that!

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

    Can you very briefly describe the solution? I'm dying to know how far away I was.

    I assumed that it's enough to consider the prisoner to start from some point on the boundary and guards can then choose where they start. Iterate over segment of prisoner, ternary search his exact position there, one guard must stand at same position, iterate over segment of the other guard, ternary search his exact position, then check with Apollonius circles who wins (well, actually find the ratio for tie).

    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится +19 Проголосовать: не нравится

      I have posted the editorial.

    • »
      »
      »
      4 года назад, # ^ |
      Rev. 3   Проголосовать: нравится +20 Проголосовать: не нравится

      It's very similar to the editorial, but in a few words:

      indeed, let's assume that the prisoner starts at the boundary. Then one of the guards must be in the same point or they'll escape immediately, so the other guard can guard only one of two segments that this point splits the boundary into. So if we compute the speed needed to catch the prisoner that runs to some point at the bottom part (via iterating over the segment we run to and using ternary search), the speed needed to catch the prisoner that runs to some point at the top part, and take the minimum of those two values, it will be a lower bound on the answer. Now we treat it as a blackbox function f(x) and try to find its maximum (I'm not sure ternary search within each segment is enough, so I had something slightly more general). I don't have a proof that the maximum of those lower bounds is the answer, I guess the editorial does :)

»
4 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

In the question C... I tried a code with dp approach but with some restriction (difference of index). It passed all the test cases.

But for this test case my code outputs 0 but the answer should be 1.

500 2

100 50 60

2100 500 500

Are the test cases of C weak or Am I wrong somewhere?

Submission link:- https://codeforces.net/contest/1427/submission/95152766

»
4 года назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

In problem C, I thought that R in the input is useless then tried solving the inequality tj — ti >= |xj — xi| + |yj — yi|, (tj > ti) to solve the problem in n*log(n) time but didn't come up with the solution, is there any such faster solution possible?

»
4 года назад, # |
  Проголосовать: нравится +26 Проголосовать: не нравится

My solution for problem G seems to be a weird modification of the standard solution.

I do binary search on the candidate values, run min-cut, then divide the vertices into two halves. Thus there will be $$$O(\log n)$$$ layers, each consisting a total of $$$O(n^2)$$$ vertices and edges. The complexity will be $$$O(n^3\log n)$$$. (Since Dinic's algorithm works in $$$O(E\min\{E^{1/2},V^{2/3}\})$$$ on networks with unit capacities)

»
4 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Difficulty of 'B' should not be less than 1500

»
4 года назад, # |
Rev. 2   Проголосовать: нравится +45 Проголосовать: не нравится

Another deterministic solution of E:

Step 1: Let $$$p \in N$$$ be the unique number such that $$$2^{p-1} < x < 2^{p}$$$. Write $$$2^p x$$$ and $$$(2^p - 1) x$$$ on board with $$$O(p)$$$ operations.

Step 2: Write $$$(2^p x) \oplus ((2^p - 1) x) = 2^{p+1} - x$$$ on the board. Then, write $$$x+ (2^{p+1} - x) = 2^{p+1}$$$ on the board.

Step 3: We can write $$$2^i$$$ for all $$$i \ge p+1$$$ on the board. Write $$$2^p$$$ by using xor operations for all the bits of $$$2^p x$$$ except $$$2^p$$$.

Step 4: Write $$$(2^{p+1} - x) \oplus (2^p) = (2^p - x)$$$ and repeat the steps with new $$$x = (2^p - x)$$$ while $$$x \ge 1$$$. New $$$p$$$ of new $$$x$$$ is strictly smaller than current $$$p$$$, so it repeats at most 20 times.

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

Can dynamic programming in Problem C be done with recursion and memoization? If yes, how? Please help.

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    Yes, taking help from the "alternative optimization" in the editorial, you can solve it using recursive DP, just make sure you don't consider more than $$$4*r$$$ of the next celebrities.

    That being said, the iterative approach is cleaner and easier, so try to practice that instead.

»
4 года назад, # |
Rev. 2   Проголосовать: нравится +22 Проголосовать: не нравится

Problem D is actually very easy if you realize the operation is same as reversing each deck individually and reversing the entire array. Since you can fix the reversing of the entire array with one operation, the problem is reduced to "sort an array with at most N subarray reverses", which is easy

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +8 Проголосовать: не нравится

    Good one!

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

    I would be thankful if you can give a quick example.

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

      Let's say array is $$$[1, 3, 4, 2]$$$ and you choose decks $$$D_1 = [1, 3]$$$ and $$$D_2 = [4, 2]$$$. Then, after the operation it becomes $$$[4, 2, 1, 3]$$$. This is the same as these two operations applied, one after another:

      1. Reverse the decks: $$$[1, 3, 4, 2]$$$ -> $$$[3, 1, 2, 4]$$$ (here each deck was reversed individually inside the array).
      2. Reverse the array: $$$[3, 1, 2, 4]$$$ -> $$$[4, 2, 1, 3]$$$

      Ignoring the second operation, according to the link I posted to the solution of the reduced problem, you would choose decks with sizes:

      • $$$[1, 3]$$$ (puts 2 in its place) and array becomes $$$[1, 2, 4, 3]$$$
      • $$$[1, 1, 2]$$$ (puts 3 in its place) and array becomes $$$[1, 2, 3, 4]$$$

      Now, to consider the second operation, you just need to keep a flag if the array is reversed or not. If it is, you reverse the decks you print. If by the end this flag is true, you print one last time: $$$[1, 1, 1, 1]$$$ (this will only reverse the array).

      Hope it is clear now!

»
4 года назад, # |
Rev. 3   Проголосовать: нравится +128 Проголосовать: не нравится

In the editorial for problem A, it's conjectured that a random shuffle works with probability at least $$$\tfrac1n$$$ (assuming the sum of all the numbers is nonzero). This is true, and here is a proof. The key claim is that, given any shuffle, some cyclic permutation of it works. This easily implies the desired result.

Suppose that the claim is false for some shuffle $$$a_1,\ \dots,\ a_n$$$ (so $$$a_1 + \dots + a_n \ne 0$$$). Interpret all indices modulo $$$n$$$. Since no cyclic permutation of this is valid, for any $$$k$$$, there exists some $$$f(k)$$$ such that $$$a_k + a_{k+1} + \dots + a_{f(k)-1} = 0$$$.

Thus, we have a function $$$f$$$ on the integers modulo $$$n$$$. (Formally, we have $$$f\colon \mathbb Z/n\mathbb Z \to \mathbb Z/n\mathbb Z$$$.) Thus, this function has a cycle, say $$$t_1 \to t_2 \to \dots \to t_k \to t_1$$$.

This gives us the $$$k$$$ relations $$$a_{t_1} + \dots + a_{t_2-1} = 0$$$, $$$a_{t_2} + \dots + a_{t_3-1} = 0$$$, $$$\dots$$$, $$$a_{t_k} + \dots + a_{t_1-1} = 0$$$. Summing these all up, we get $$$c(a_1 + \dots + a_n) = 0$$$, where $$$c$$$ is the number of "revolutions." Thus $$$a_1 + \dots + a_n = 0$$$, as wanted.

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

    Very cool! If you don't mind, I will add a link to your comment in the editorial.

    UPD: Added.

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

    Thus, we have a function f on the integers modulo n. (Formally, we have f:Z/nZ→Z/nZ.) Thus, this function has a cycle, say t1→t2→⋯→tk→t1

    I didn't get this. Will you please elaborate on it?

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

      Recall that for each $$$k$$$, we have an $$$f(k)$$$ for which $$$a_k + a_{k+1} + \dots + a_{f(k)-1} = 0$$$.

      Now draw an arrow from $$$a_k$$$ to $$$a_{f(k)}$$$ for each $$$k$$$. Since we have one arrow leading out of each term, there must exist a cycle of arrows. (To see this, imagine following the arrows: travel from $$$a_k$$$ to $$$a_{f(k)}$$$ to $$$a_{f(f(k))}$$$, etc. Then eventually we must revisit some term, which gives a cycle.)

      Suppose the cycle takes $$$a_{t_1}$$$ to $$$a_{t_2}$$$ to $$$a_{t_3}$$$ to ... to $$$a_{t_k}$$$ to $$$a_{t_1}$$$. Now we can follow the last paragraph of the proof.

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

    That's pretty good! I think the below also works as proof (correct me if I'm wrong).

    In the case where n-1 numbers are 0 and one is non-zero, the only possible permutation that gives you an acceptable answer is when non-zero number comes first. Probability of that happening is 1/n. Probability will keep decreasing as you replace non-zero numbers with 0, so the lowest positive probability is 1/n.

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

I have a straight forward solution for E with no randomization or coprime numbers required.

Let k be the MSB of x. Notice that we can get 2^n * x for all n by adding x to itself and then repeating. Now, for any number on the board y, we can set all bits >= k equal to 1. We can do this by xor-ing 2^n*x to set each bit above k if it is not set for some appropriate n. So we just need to find two numbers for which, after setting all bits >= k to 1, all of the bits below k are the same, except the 1 bit. We can just check the first 3e6 multiples of x (no randomization required).

Submission: https://codeforces.net/contest/1427/submission/95156859

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I solved problem C the way you suggested and thought that 2rn = 10^8 will not fit so I didn't implement it...
Did this happen to anyone else?

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится -7 Проголосовать: не нравится

    Sadly same thing happened with me, I was trying to think of applying segment tree on n but it got too messy. Hopefully I would have tried D first which was relative easier to me.

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

    I implemented as said in the tutorial. Hope it helps :) Solution

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

    Same. Was able to think O(nr) and was like 10^8? No that won't work.

»
4 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

95127605 I used random_shuffle for problem A because the constraints were small whereas everybody else used sorting. Is it my luck that my submission got accepted? Also, what are the chances that my solution won't work?

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

For E, I had similar solution to the gcd one, but the step of finding a co-prime pair is randomized. It randomly generates new numbers until it finds a co-prime pair. It too completes in $$$\le 100$$$ operations. 95149535

»
4 года назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

one of the best editorial. Loved it!!

»
4 года назад, # |
  Проголосовать: нравится +10 Проголосовать: не нравится

if it is possible, try to keep hints option in every editorial .. it is so beneficially for a newbie like me :)

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I like the solution to E with bezout theorem very much! Thanks for fast editorial.

»
4 года назад, # |
Rev. 3   Проголосовать: нравится +1 Проголосовать: не нравится

Could you check pls what is wrong with my solution for C (WA15)

code
»
4 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

I stupidly misread the constraints for D, and even more stupidly called my results vector in the solution "omgconstraints", as a way to punish myself for not reading constraints, by typing that name like 50 times. Given that my successful submission for D was 10 seconds before the contest ended, I cursed myself every time i typed "omgconstraints" rather than the usual "res" that I use. Had I known that these extra letters might have pushed cost me the problem, I would have definitely thought twice.

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

Hey, I have some problems with B.

Just Have a look at this test case and tell me how's the answer for this test case is 16.

1

12 2

WWLWLLWLWWWL

Ans:- 16 I think the answer should be 15

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

In problem C.Who can explain completely Hint 3 ?

»
4 года назад, # |
  Проголосовать: нравится +71 Проголосовать: не нравится

Based on this contest, I believe that dario2994 is one of the best problemsetters on CF. Would love to see another contest from you!

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

Can someone explain step1 of the deterministic solution of Problem E . Particularly this line :- y=(2ex)^x=(2e+1)x−2e+1 and therefore gcd(x,y)=gcd(x,2e+1)=1

»
4 года назад, # |
  Проголосовать: нравится +10 Проголосовать: не нравится

Who is an "experienced participant" in your view dario2994?

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

Hi, Can anyone help to understand why my solution of problem D works. Here is the link to solution : SOLUTION

Approach: I am counting the number of operations from 0.

When the parity of number of operation is even : In this case I select subarrays staring from first element till the elements are in decreasing order. When I find an element that is bigger than previous element, I stop and considers the chosen elements as a split. Now I start fresh from this element and repeat this process until I have some k splits. Now I perform the operation on them.

When the parity of operation is odd, I am doing the same process except I chose subarrays that are strictly increasing.

For example : Input:

5

4 2 1 5 3

Output:

2

3 3 1 1

4 1 2 1 1

Given 4 2 1 5 3:

Operation 0 : Parity = 0

We split as (4 2 1) (5 3)

New array : 5 3 4 2 1

Operation 1: Parity = 1

We split as (5) (3 4) (2) (1)

New array : 1 2 3 4 5

We get the sorted array.

I am not able to prove why this works. I saw this pattern during contest but forgot about the case that k should not be equal to 1. Is this same as the approach given in the editorial intuitively ?

»
4 года назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

This is what I did in problem D.

Idea: for 1<=i<n we get i and (i+1) adjacent keeping everything else(less than i) adjacent. (Similar to the editorials idea). Hence in at most n-1 moves we can get the array sorted and 1 extra move if the array turns out to be descending.

So let us say we have first i numbers sorted(descending or ascending). We have 4 possibilities. D4587a81dcfc82f2a.jpg

The indicated boxes are how we can achieve our idea.

After this the code is fairly simple.

»
4 года назад, # |
  Проголосовать: нравится +62 Проголосовать: не нравится

As asked by the dario2994, I have some feedback to offer. Some of the below points are for the a part of community who miss no chance to rant the organisers. So here we go.(expecting a lot of hate from those who can't agree diverse thought process)

What I loved about the contest:

  1. The contest in general was awesome. It was one those contests that kept me thinking about the problems for the entire time rather than reaching a point where one realises that later problems ain't their cup of tea. (Kudos for this because such contests are rare to find).

  2. The contest had a vast range of problem. Many people are of the view that contest was filled with ad-hoc ones, but I beg to differ. I think we can call these problems as non-trivial/non-standard rather than ad-hoc. (I know lot of people would disagree to this)

  3. The contest is an excellent example where the problem statement are not exactly short yet very interesting to read. I can't stress enough that length of problem statement doesn't matter as long as the description is to the point and doesn't make things messy to understand. As for me, I didn't loose interest in reading any statement and I read all of them (yes all until H) even though I knew I wouldn't be able to solve them realistically.(I expect most hate for favouring the length of problem statements).

  4. The contest had excellent sample cases. I can bet that without such samples a lot people would have had series of WA on pretest for question B.

  5. The contest had really high quality problem (even though I couldn't solve many problems doesn't take away the fact). I would genuinely like to appreciate the quality of the problems and beautiful ideas behind the solutions.

What I think could have made contest more interesting:

  1. I believe that scoring distribution could have been better than what it was. Of course this point applies iff one is able to solve problems else it is irrelevant. But I strongly believe that scoring can be made better by comparing the problems within a contest (and not with other CF rounds) relative to each other. I liked the math the errichto proposed to the author in one of his comment but I also understand that it is very hard to gauge the exact difficulty of problems just from handful of testers and that the actual round can have variations to this. I think that this round could have had been relatively high scoring (by increasing the point of C and onwards problems) or could have been low scoring (by decreasing the points of A and B). All I am trying to convey is that scoring could have been better distributed.

But overall, I'd place this contest in top 10-15 of all I have appeared in (appx 200 or more across various platforms). I'd sincerely appreciate the hard work of author and coordinators for making such a nice contest.

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +27 Проголосовать: не нравится

    Thank you for the feedback (and don't worry about downvotes).

    Regarding 4., I have to thank testers for this. Initially samples for B were much weaker and many testers complained.

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

So we are basically optimising $$$ O(n^2) $$$ dp solution for Problem C. My question is how do we optimize it if there is no $$$ \triangle{t} \ge 2\cdot{r} $$$. Won't it run on $$$ O(n^2) $$$ and give a TLE. Or am I missing something out? Thanks and Great Round.

Edit :

Got it. $$$t(i)<t(i+1)$$$ that limits maximum iterations to $$$2r$$$ and complexity to $$$O(2nr)$$$.

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I did come up with the $$$O(nr)$$$ solution for 1427C - The Hard Work of Paparazzi, but I thought it would not fit into the time limit :(

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I use another optimization in problem C and also get accepted: 95139974 My brief idea is using ans[i] to store the maximum photos can be taken when we already at i'th celebrity. We iterate from ans[n] to ans[1]. For each ans[i], instead of iterating all celebrities in [i+1, n], we use a map to record the ans[j] (j in [i+1, n]) in descending order, so we can just take the first celebrity that satisfies $$$|x_i-x_j| + |y_i-y_j| \le t_j-t_i$$$.

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

For problem C, is it possible that two consecutive celebrities appear at the same intersection?

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

    That has to be true for any test case where n > r * r according to the pigeon hole principle.

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

My solution for E:

  • try various inputs, bruteforce and print some shit to get an intuitive understanding
  • notice that the worst case is when $$$X$$$ is a simple binary palindrome 1000...1 and we need to create numbers approx. up to $$$X^2$$$ then
  • we want to generate a smaller (than $$$X$$$) number $$$Y$$$; if it's even, we can remove the largest 1-bit from $$$X$$$ using it, and if it's odd, we can solve recursively for $$$Y$$$ (there's the operation limit, but this recursion turns out pretty fast)
  • this seems to work for the palindromic case: try XORs of $$$X$$$, $$$2X$$$, $$$4X$$$ etc. up to $$$2^k X$$$, for each $$$2^k$$$, pick one of these (denoted by $$$A$$$), then $$$B = A \oplus X$$$, then create $$$(A+B) \oplus (2A)$$$ or $$$(A+B) \oplus (2B)$$$, and it turns out to be smaller than $$$X$$$ for a good choice of $$$k \le 20$$$
  • bruteforce check if it gives $$$Y \ll X$$$ for each $$$X$$$
  • it works and any odd $$$Y$$$ is around 2 times smaller than $$$X$$$! implement

I don't want randomised solutions because they carry a risk, but my thinking here is way more random. I have no idea why this works.

»
4 года назад, # |
  Проголосовать: нравится -18 Проголосовать: не нравится

I like problem D. And I believe I'm producing nicest solutions out of all solutions I've looked at. :) 95384262

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Anyone able to provide proof as to why we only need to consider 4r consecutive celebrities ? I'm not able to figure it out as I think, as said in the editorial, any element past the 2r point will be a compatible point. What different happens at 4r ?

Thanks in advanced!

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +10 Проголосовать: не нравится

    If the last celebrity you're choosing before celebrity $$$k$$$ is celebrity $$$i<k-4r$$$ then you can get a more optimal solution by also choosing celebrity $$$k-2r$$$ because you can always get both from celebrity $$$i$$$ to celebrity $$$k-2r$$$ and from celebrity $$$k-2r$$$ to celebrity $$$k$$$, so choosing $$$i<k-4r$$$ is never optimal.

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

the author was playing jailbreak on Roblox when he was thinking about the last problem.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I have an alternate solution to problem E: doesn't use any number theory theorem.

First of all, let's assume the number we have ends with $$$01$$$ and not $$$11$$$. If it ends with $$$11$$$, we can XOR it with its double and make it end with $$$01$$$. So we start from a number ending with $$$01$$$ : lets say we start from $$$x$$$.

form a number $$$c$$$ which is $$$x$$$ shifted left $$$k$$$ number of times, where $$$k$$$ is the bit length of $$$x$$$.

Then we XOR : $$$x+c$$$ and $$$x \oplus c$$$.

Hence we get a number $$$d$$$ which is a pure power of $$$2$$$, and is the smallest power of $$$2$$$ which is greater than $$$x$$$.

Now we will use this number $$$d$$$ to remove the highest bit of $$$x$$$: Keep multiplying $$$x$$$ by $$$2$$$, and whenever we have highest bit of $$$x$$$ and $$$d$$$ colliding, XOR them. Do it until only one bit in $$$x$$$ remains. Because $$$x$$$ ends with $$$01$$$, we get a power of 2 which is less than $$$d$$$. Use this to chop off the highest bit of $$$x$$$.

Keep chopping off the highest bit of $$$x$$$ until we get $$$1$$$.

Code