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

Автор mesanu, история, 3 года назад, По-английски

1537A - Arithmetic Array

Tutorial
Code

1537B - Bad Boy

Tutorial
Code

1537C - Challenging Cliffs

Tutorial
Code

1537D - Deleting Divisors

Tutorial
Code

1537E1 - Erase and Extend (Easy Version)

Tutorial
Code

1537E2 - Erase and Extend (Hard Version)

Tutorial

Solution by Ari.

Code

1537F - Figure Fixing

Tutorial
Code
Разбор задач Codeforces Round 726 (Div. 2)
  • Проголосовать: нравится
  • +154
  • Проголосовать: не нравится

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

This was faster than the system testing!

Thank you!

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

Horribly weak pretests for E1 and E2 :(

Not to mention long queues.

Round should be unrated!!!

MikeMirzayanov Monogon mesanu SlavicG

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

    My guy, you haven't seen long queues, this one was no longer than 3 mintues. I saw 40 minutes long queue. Also, if you didn't think before submitting E1 or E2, it's on you. Please refrain from posting such non-sense next time.

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

      Can someone explain why long queues mean the round might be unrated? Is it cause we'll not be able to check whether our solution has passed?

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

        Pretty much so, but the queue has to be extreme to lead to an unrated round.

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

    Although we regret not making stronger E tests, poor test quality isn't a reason to make the round unrated.

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

    What's the issue with pretests? Difficult problems are meant to challenge the coder. If the organizers give you large pretests so that you can find every corner case with ease, it would be useless.

    Round is fine.

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

      Difficult problems are indeed meant to challenge the coder. But I don't think that means you make a person think he's got the answer right when he hasn't, hence making him solve the next question when he hasn't solved the previous one correctly.

      Also, I don't think giving WA on the pretests would as such help too much in finding the corner cases, its just to tell the contestant that you haven't yet got this question right and he should continue to work on it.

      Round is fine though, only a minor issue which isn't enough to make it unrated.

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

    I did fall prey to the weak pretests of E1. (Pretests passed but not accepted)

    But I don't think that's enough reason for round to be unrated. Questions were good and above all, it was my fault that system tests didnt pass.

    Round should unrated only if questions are super ambiguous or online judge takes too long to give verdict on submission

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

Adhoc Adhoc everywhere :0

I enjoyed the contest btw and I really wish you guys make more of these. Kudos (Y)

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

I'm such an idiot for not solving B but solving C

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

How accepted solutions for problem E1 rose so quickly ?

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

No original problems, just dumb adhoc problems

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

F:"It is guaranteed that the graph is connected."

There seems to be no guarantee of this condition.

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

    It says the graph is connected in the first sentence and again in the input section.

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

In problem E, one can prove that

$$$ a^{\infty}<b^{\infty}\Longleftrightarrow a+b<b+a $$$

So just compare the prefixes using Z function.

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

    I have done the same. But my answer is failing for test case 43 in E1 and 93 in E2

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

      Me too, and my fault is that I forgot to judge a sqecial situation, when a suffix of the string is also its prefix, you need to cut out the suffix to get a better answer.

      Prove:That's because if you found $$$S[1,n-i+1]=S[i,n]$$$ ,it means you've already judged suffix starts from 2 to i-1, ans all of them are smaller then itself, now we judge if we cut the $$$i^{th}$$$ suffix, if we cut it, we will connect itself to it after cutting(we call it s1 ans the one that didn't been cut s2), and it can be proved that the first place that may be different is the $$${n+1}^{th}$$$ place of s2, and it is the initial string again,for s1, it is the suffix from (n mod (i-1)+1) we know that if s[x] means the suffix from x,$$$s[j(1\le j \le i)]\le s[1]$$$,so $$$s1\le s2$$$, we need to cut it.

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

        How do you check if a suffix of the string is also its prefix? I did using set(stored all prefixes and then created suffixes one by one) but got MLE.

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

    Catch Jiangly and ORZ%

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

    What's the intuition behind this equivalence? After thinking for a while I was able to find a proof, but how do you come up with it in the first place?

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

      I have solved a problem about arranging some strings, where I needed to prove the latter relation is transitive, so I discovered and remembered this equivalence.

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

      Will you please provide the proof for the above relation?

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

      I'm a bit late, but here is some more or less intuitive proof. We can look at strings as base-p numbers (here $$$p=26$$$, but it doesn't really matter). Obviously it's enough to compare string consisting of $$$|b|$$$ copies of $$$a$$$ with string consisting of $$$|a|$$$ copies of $$$b$$$. In other words, we want to compare \begin{gather*} \sum_{i=0}^{|b|-1}a \cdot p^{|a|i}\quad vs \quad \sum_{i=0}^{|a|-1}b \cdot p^{|b|i}\\ a \cdot \frac{p^{|a||b|} — 1}{p^{|a|} — 1} \quad vs \quad b \cdot \frac{p^{|a||b|} — 1}{p^{|b|} — 1}\\ a(p^{|b|} — 1) \quad vs \quad b(p^{|a|} — 1)\\ a\cdot p^{|b|} + b \quad vs \quad b\cdot p^{|a|} + a \end{gather*}

      And the last line is just $$$a + b$$$ vs $$$b + a$$$ (here $$$+$$$ is concatenation)

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

        I cannot understand what do you mean by $$$a.p^{|a|i}$$$ in the summation formula. Can you please elaborate more?

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

          To concatenate numbers you need to multiply one of them by some power of base. For example, if $$$a = 123$$$ and $$$p = 10$$$, then $$$|a| = 3$$$, and \begin{gather*} 123123123 = 123\cdot 10^6 + 123 \cdot 10^3 + 123 \cdot 10^0 = \sum_{i=0}^2 123 \cdot 10^{3 i} \end{gather*}

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

        Thanks man! Its amazing how things simplify after you see strings as numbers with base 26.

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

      Can you please tell what proof you came up with? Thank you.

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

.

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

For D, I just printed the answer for the first 100 natural numbers and found the solution...

Hopefully, I will become Orange today after 15 months :)

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

I was thrilled to find I was able to do 5 questions only find they were of div3 difficulty overall nice round thanks for the contest

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

Woow !! fast editorial Thanks :)

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

Problem D: Can someone explain me the reason for "If number is odd then opponent (BOB) will always win"?

I didn't get it.

Thanks

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

    for odd you will have divisor odd ,now if you subtract odd number from odd number you will find even number for even numbers you may refer above in editorial

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

    If n is odd, then in the first move Alice have to choose odd divisor. and if u subtract a divisor from a number then that divisor also remains divisor of the new n.

    so bob will just choose the previously taken odd divisor of alice, and since the number is odd so it will be zero after odd time of subtraction. (odd*odd=odd). and the last subtraction will be made by alice (because total number of subtraction is even),and alice will make the number zero means he is subtracting the complete number so alice will loose.

    Hope you will understand thanks!!.

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

The problemset was fairly interesting.

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

Check out my simple greedy solution for E2. 119887467

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

    Can you please explain the else if statement?

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

      You can cosider the given testcase s= dbcadabc. When i=4(0 based indexing) s[i]==s[j], then we will take this character in our prefix if the next character {(i+1)th} is less than or equal to s[1], which is 'b'. If that also came to be same then we will check the next one, like in this example , s= dbcadbbc, we will compare s[6] with s[3].

      I know it's a bit hard to understand, but I have tried my best :)

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

    Underrated

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

    Very clean soltuion!

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

    Great solution.. I saw many solutions but all of them talked about some Z function.. I am glad I ran over this one.. Thanks alot

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

    nice solution

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

    Thank you for making this problem soo simpler to understand.

    One point I would like to mention is: In second condition we don't need to take modulo, as j will always be smaller than i and even if j exceeds (last+1), substring starting from s[0] will be equal to substring starting from s[last+1].

    link to solution

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

Problem statement was quite clear.awasome explanation.

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

contest was really good but a little bit easy than other div2 rounds

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

E1 Test 43 should have been a pretest.

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

Problem D is amazing!

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

For E2, I have a simpler solution that, I believe, implicitly uses the Z-function concept, however is not at all a prerequisite to understand. Also, I’m not 100% sure about correctness; feel free to hack in that case.

The editorial for E1 establishes the fact that the optimal answer is merely a repetition of a prefix. We will check which prefix length is optimal to be repeated, starting from $$$1$$$ to $$$N$$$. Let the current optimal length of prefix be $$$len$$$.

The casework is similar to what is described in the editorial for E2:

If $$$s_i > s_{i\, \%\, len}$$$ (0-based indexing here), the prefix should not be extended any further; no prefix beyond this point is optimal, and it is optimal to keep repeating our current optimal prefix. So we simply break.

If $$$s_i < s_{i\, \%\, len}$$$, it is more optimal to extend our prefix up to this point; hence we do it, i.e. set our optimal prefix length to $$$i + 1$$$. This needs some more explanation, so bear with me for the next couple of lines.

There’s also the more interesting case of $$$s_i = s_{i\, \%\, len}$$$, but before that, let’s establish an invariant: So far in the algorithm, the string made by the repetition of the prefix, and the substring $$$s[0:i]$$$; both are equal. How? Well, we break when $$$s_i > s_{i\, \%\, len}$$$, and in case of $$$s_i < s_{i\, \%\, len}$$$, we simply extend our prefix up to here, making it equal.

Let’s deal with the $$$s_i = s_{i\, \%\, len}$$$ case now: Here, we cannot decide at this moment, whether repeating the current prefix or extending the prefix up to this point is more optimal. Hence, we just proceed ahead.

Further along the line, if $$$s_i > s_{i\, \%\, len}$$$, we realize that repeating our current prefix is indeed the most optimal, and we need not check further, just like in the previous scenario. Hence we break.

However, if $$$s_i < s_{i\, \%\, len}$$$, we realize our prefix repetition was non-optimal; how do we go back, i.e. change our prefix now? That’s where our invariant comes in. Our prefix repetition string was equal to the substring $$$s[0:i - 1]$$$, and becomes unequal at index $$$i$$$; hence extending our prefix length simply means changing the prefix to $$$s[0:i]$$$.

This helps us maintain an $$$O(N)$$$ solution. 119889474

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

    Your code is nice and simple. But didnt understand your casework for the case when si = si%len (in your code, you are not dealing with this case separately as well).

    You say "Here, we cannot decide at this moment, whether repeating the current prefix or extending the prefix up to this point is more optimal. Hence, we just proceed ahead.", but you are never comparing these two possibilities in further execution. You are just assuming that current answer will be better until you find the next mismatch.

    For example, your third last paragraph says that you are breaking the loop if you found si>si%len, but this just tells you that the retained prefix is a better answer than current index, however you are still not comparing with the other possibility which you ignored previously. What if you would have achieved a better answer using that prefix?

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

      Thank you for pointing this out. I believe my write-up is still incomplete, and the $$$s_i = s_{i\, \%\, len}$$$ case requires another explanation. Let me rewrite this particular case.

      When $$$s_i = s_{i\, \%\, len}$$$, I now claim that maintaining our original prefix is always more than, or equally optimal to changing to this prefix.

      Proof

      Hence, in our algorithm, we make no update to the optimal prefix length, and proceed forward. This should make the solution more complete, if not fully.

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

        Yes, now your solution is complete :) I`ll also suggest the authors of the editorial to mention that in the si = si%len case, its safe to assume sticking to the current prefix is a better choice than switching.

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

          Can you please prove or explain these two things:

          1. From the third paragraph, "Hence, we are simply left with proving that $$$pref_{len(x)−len(y)}(x)>=suf_{len(x)−len(y)}(x)$$$ to prove that our current prefix repetition is optimal." Why does this imply our current prefix repetition is optimal? I think in the case of equality $$$(pref_{len(x)−len(y)}(x) = suf_{len(x)−len(y)}(x))$$$, we also need to check further by comparing the string $$$xxxxx...$$$ starting at the third $$$x$$$ with the string $$$suf_{len(y)}(x) + yxyxy...$$$

          2. From the last paragraph, "This means there exists an $$$i$$$ where $$$pref(x)[i]<suf(x)[i]$$$. This can actually be avoided by repeating a prefix smaller than our current optimal one, but this shows that a smaller prefix length yields a more optimal answer, which violates the invariant of our algorithm." If $$$len(y) > i$$$ (0-based indexing), we can repeat the prefix of length $$$len(y)$$$. However when $$$len(y) \le i$$$, I couldn't find any prefix of $$$x$$$ to repeat that yields a more optimal answer.

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

Thanks mesanu SlavicG for such a great round . Today I got my best rank .

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

I am getting a runtime error for the solution of 1537C - Challenging Cliffs. Will anyone please help me. Here is my solution submission:

Thanks in advance!

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

    Your value of mini is — 9e7 + 9999999. It should be 9e8 + 99999999 :)

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

    In order to avoid this kind of mistake, I suggest initializing mini as the difference between the first two elements of your sorted array, as n is at least 2, and just do the loop from i=1

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

When you brute-force problem D for small N and spot the pattern :

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

I finished E1 10 seconds before the round finished. Wasn't able to submit :(

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

To get difficulty n−1, we need mk to be the shortest mountain and mk+1 to be the tallest mountain. This will only happen if n=2. Regarding the Problem C tutorial, This can also happen for n>2 when all elements are the same, isn't it?

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

I see a lot of people getting relatively low positive delta (even negative delta) because of the cheaters. This is so unfair!

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

In problem E, can someone please prove why it's optimal to keep duplicating a prefix? The editorial's proof isn't clear to me.

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

    Think like this, might be helpful. Without loss of generality in the first step you have to double some prefix (after deleting some characters from the end). As these are the only two operations available. So initially you want to double something which gives you maximum advantage i.e it is at least smaller than the initial string given to you, in fact, you will select the very first occurrence of the prefix that when doubled is smaller than the original string given. So in brute force double every prefix and check if it is smaller than the original string. When you find one break. now suppose you have selected prefix P and now you are getting PP after doubling. Now you perform the same step as above i.e finding some prefix of PP which when doubled gives smaller string than PP. And I can assure you , you will not find any such prefix in the new string PP which will give you advantage as in earlier case (Just work it out). So you are left with only option of repeating P, as this will at least not give you lexicographically bigger string. Hope this helps.

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

      Now you perform the same step as above i.e finding some prefix of PP which when doubled gives smaller string than PP. And I can assure you , you will not find any such prefix in the new string PP which will give you advantage as in earlier case

      in fact, you will select the very first occurrence of the prefix that when doubled is smaller than the original string given.

      I couldn't prove either of these.

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

      let s="abca" k=10, P="abc" then PP= "abcabc" and PPPP= "abcabcabcabc" .But from PP if we take PP'="abcab" then PPPP'= "abcababcab" which is smaller than PPPP.Your proof fails here.Correct me if I am wrong.

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

        Why will you choose initially abc? Choose initially P="a", that will give smallest lexicographic string.

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

Nice round! Easy version of D. I got bamboozled because of it.

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

Codeforces 726 Div2:E1 solutions implementations: so innovative these guys : ) (not even in variables in some solutions and getting +100 or so)! 119889554 119889070 119884298 119890054 PS: check their other solutions similarities in every aspect! Please,Strict actions should be there. MikeMirzayanov (sorry for disturbing)

Mass-copying

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

Has anyone managed to pass E2 using binary search and hashing. I know in that 2s TL it won't pass as it will be nlog(n) and is giving TLE. But now I saw binary search in the tags. So just curious to know has anyone passed using binary search.

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

    119900135 one of my friends solution.

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

      Thanks, man. I was calculating the power inside binary search which was creating an extra log factor, precalculating power fixed the issue.

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

        Can you explain your binary search based solution please?

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

          sure, Actually, I am simulating the Z function using binary search as I don't know Z function :(

          First precalculating the hash of the string and the prefix hashes. Now if for each index i I want to find out the first index where the prefix from 0 to i-1 and string starting at i differ.

          To do that I am using binary search. Before the first mismatch of both strings, both the hash values will be same , using this fact in binary search to find the first mismatch character and checking whether it is smaller or larger than that position in the prefix.

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

            Two questions:

            1. Is your hashing collision free?

            2. Can you explain why are you doing this "Now if for each index i I want to find out the first index where the prefix from 0 to i-1 and string starting at i differ"

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

              Well technically no hash function can be collision free I guess. But the probability of collision is very very less I believe.

              Also for this "Now if for each index i I want to find out the first index where the prefix from 0 to i-1 and string starting at i differ". As far as I know Z function does exactly this, i.e it returns the longest prefix where s and the string starting at i match. And secondly I need to know this to know whether doubling this prefix will give me better answer or not, by comparing the first mismatch.

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

Can someone explain the thought process/idea behind D? I am finding it difficult to grasp the editorial.

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

    if n is odd, for eg 15, so their factors are 1,3,5,15(that it's all odd) you can see if we subtract any divisor D, the number will be even, but it cannot be a number of the form 2^k, because

    • (n%D)==0, so we subtract D from n, it becomes n-D and it must be divisible by D, so n-D, cannot be in the form of 2^K.

    so this implies if the starting n is odd, then Alice will make it even, and similarly, Bob will make again the number odd since a prime number is either 2 or the odd number, so Alice always gets the odd number, and hence Alice will lose.

    if n is even and not in the form of 2^K, so similarly Alice will always make it odd and so, Alice will win.

    Now, if n is of the form 2^K, then k times the game will be played, if both play it optimally, otherwise the one who don't half it will always lose, for eg 16 = 1, 2, 4, 8, 16, if Alice chooses 2 then it becomes 14 and it is the even number (not in the form of 2^K), so Bob will win. So, both try to half it at every step, so if k is odd then Bob will win otherwise Alice.

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

I`m seeing solutions for E2 where people are not dealing with the case si = si%len at all (going by the editorial, that part is important as well).

Can anyone explain how these solutions are working?

Example: Here

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

Just a small detail and boom, lost 2 problems :(

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

I don't really get how my solution to problem E2 works lol. First of all, I only chose the shortest prefix which is lexicographically smaller than the whole string. Moreover, I found this first prefix naively by comparing char by char after compressing same consecutive characters. (So the string "aabcccb" gives the array {2, 1, 1, 3, 2, 1}. Each cell is the length of the jump to first different char). I don't understand why it is correct and why I don't get TLE. If someone could explain it would be cool. Solution: https://codeforces.me/contest/1537/submission/119930955

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

The sample code solution for 1537C — Challenging Cliffs seems wrong, or not?

It'd produce $$$m_{k+1}, m_{k+2}, ..., m_{n}, m_1, m_2, ... m_k$$$, which is not what is described in the tutorial.

Or have I misunderstood anything?

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

E1/E2 should contain multitests and every short(length<=4) string should checked the pretests :(

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

System testing was slower than internet Explorer. XD!

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

Problem F is nice.

Tried to cover all the observations in my solution video :) Explanation Link

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

I think just a KMP-like algorithm can solve E2 by greedy.

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

Maybe there is a problem which used a conclusion pretty like problem F(in Mandarin) You can see the conclusion there(also in Mandarin)(maybe u can use google translate :))

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

For E2: At i-th position, I just compared the i-th prefix with the n-th prefix and got AC 119938778

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

I guess problem D was the most interesting one rest were pretty easy!

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

MikeMirzayanov I think the rating points given for this contest needs to be re-evaluated, as I didn't solve any problems, with -3 penalty, still I got +37 for this contest whereas all others who solved one or more problems got negative points, pls take a look.

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

My Simple greedy Solution for E2 119941150

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

Does anyone come up with answer for D without bashing a bunch (like first 50) of small case? It wasn’t until I write a code to look at first 2000 answers that I spot the $$$2^k$$$ exception. I want to know the intuition behind this pattern if someone come up with it without bruteforce pattern to look.

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

    I tried to find some strategy or some sort of invariant which Alice can use to win. I wrote $$$n$$$ as $$$n = 2^k N$$$. Alice can give Bob $$$N(2^k - 1)$$$ which has all odd divisors and Alice is guaranteed to get an even number again. Now only exceptions are when $$$k = 0$$$ or $$$N = 1$$$.

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

wonderful solution B,i can't realize this solution in contest so that i write 84 line code to ac...

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

include<bits/stdc++.h>

using namespace std;

define ll long long

int main() { ll t; cin>>t;

while(t--)
{
    ll n;
    ll a[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[n];
    }
    sort(a,a+n);
    ll index1,index2;
    ll min=10000000007;
    for(ll i=0;i<n;i++)
    {
        if(abs(a[i]-a[i+1])<=min)
        {
            min= abs(a[i]-a[i+1]);
            index1=i;
            index2=i+1;
        }
    }
    cout<<a[index1]<<" ";
    for(ll i=0;i<n;i++)
    {
        if(i!=index1 || i !=index2)
        {
            cout<<a[i]<<" ";
        }

    }
    cout<<a[index2]<<endl;
}

} can anyone tell me where am i wrong in this code?? this a solution of c

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

    You forgot cin >> n;

    UPD. In the first loop, where you read the array, you have cin >> a[n]; instead of cin >> a[i];

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

insight I used for E1/E2:

a bit long but simple
»
3 года назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

problem D was same as this leetcode problem: link

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

    But LeetCode problem gives $$$n \le 10^3$$$, whereas the Codeforces edition has $$$n \le 10^9$$$. This makes the problem drastically harder because a naive memoization/recursion will work on the LeetCode, but not the Codeforces rendition.

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

Help!!! Why my solution to problem E2 failing at case like 'baaaaaaaaaa...'. I precomputed the LPS and used it to compare the characters. Checker cmnt is also not showing any difference.(https://codeforces.me/contest/1537/submission/119930117)

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

I had a different solution for D. Calculate the prime factorisation of $$$n$$$.

Let it be, $$$n=p_1^{k_1}\cdot\ p_2^{k_2}\cdots\ p_m^{k_m}$$$

Let $$$S=(p_1-1)*k_1+(p_2-1)*k_2+\cdots +(p_m-1)*k_m$$$

Now we can reduce $$$n$$$ until it becomes some $$$p_i$$$ or $$$1$$$.

Then possible moves players can make are: $$$S -p_i $$$ for some $$$p_i$$$ in prime factorisation of $$$n$$$ .

Check if any of these possible moves are odd, then there is always winning state for Alice otherwise Bob will win.

More explanation

Solution:https://codeforces.me/contest/1537/submission/119883715

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

    That's a nice approach to the problem. But as $$$\sum(p-1)$$$ is even $$$\forall p\ ( p \in prime \land p \neq 2)$$$, we only need to check power of $$$2$$$. For an odd number of moves either $$$n$$$ must have an odd divisor or power of $$$2$$$ must be even. I think this then reduces to the same as the editorial proof.

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

https://codeforces.me/contest/1537/submission/119973061 this shouldn't pass right? or some proof or logic explains why it passed?

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

Why 2-pointers is not in the tags for E2 ? submission . EDIT: Now 2-pointer is there.

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

This round was easy compared to previous div2 rounds

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

How to solve problem F if It is NOT guaranteed that the graph is connected . Then do we have to check for each connected component separately??

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

    Huh? You have a connected undirected graph made of n nodes and m edges. It literally says it's connected.

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

      No, I'm saying what is if the problem said that its not necessary that graph is connected then how to solve that problem !!

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

Really poor Editorial for F. You just stated a bunch of necessary conditions and didnot bother to prove that they are sufficient. can mesanu or anyone explain why sums of both colors being equal in the bipartite case is sufficient ?

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

    For Bipartite:

    Let's suppose two colors are black and white. We can solve for black by adding using the edge connected to those nodes. With this, we also get that we change white by that amount, so the sum in white is the desired sum.

    Now, suppose some node is not working yet. Then, it must be in white and there must be another node that still doesn't work. Find those two, then we find any path connecting those. This path will have an even length (because we traverse from white to white) thus we can do something like +a, -a, +a, ..., -a. This operation would increase the first node by a, reduce the endpoint by a, and do not affect the rest. Thus, we reduce down one white node. Doing this until no node (that doesn't match) left is possible since the sum in white is already the sum we want after we doing black. So, we are done.

    For the sake of completion, let me explain the case of not bipartite as well.

    We can do the same coloring scheme, and we can increase or decrease the sum of white color to match that. Then, we delete those out and left with a spanning tree which is bipartite. Thus, we can follow the same algorithm to solve those nodes colored in white.

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

      Can u explain the case for not bipartite again?? What are u deleting to get a spanning tree??

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

        Suppose we get a (non-bipartie) graph G, we can find one spanning tree called T. Then, we color black-ans-white corresponds to T. Since G is not bipartite, there exists node connecting same color. WLOG, it’s white. Then, we can solve for black in the same manner, and change sum-value of white using that node. Finally, we focus back to T and use only edge inside T, we would get same scenario as I described in bipartite case.

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

E1 editorial not clear. the proof part

someone help me pls

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

Nice problem, not very difficult but make me cry. qwq

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

anyone got the binary search solution for e2? i'm not quite familiar with that z-function (i'm planning to learn it soon, but it would be nice to know different solutions)

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

anybody give me the link of video solutin of e2 problem ,i learned about the z function but i did'nt understand the solution and editorial please help me

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

In problem F, when the graph is bipartite, I can understand that when the condition "sum1 equals sum2" not holds, the answer is No. But I can't understand why answer is Yes when the condition holds.

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

I got a greedy algorithm on E1 problem, and I failed test 5. Can you tell me why I was wrong? Thank you! My solution: https://codeforces.me/contest/1537/submission/119877862

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

    try 4 8 cacb

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

    for index i, just checking if it is greater than s[0] or not and then replacing rest of the part is not enough. Even if(s[i]==s[0]),check if(s[i+1]>s[1]) and so on. If s[i+j]>s[j] such s[i+j']==[s[j'], 0<=j'<j then also s can be repeated from i onwards. Consider the case

    6 6
    dcbdce
    

    correct ans is 'dcbdcb' not dcbdcd

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

I don't understand the proof in the E1. "Let's relax the requirement so you have a position in the string and each time you either return to the beginning or advance to the next character." What is meant by above ?

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

This is the easiest "Two pointer approach" for E1 and E2.
119946716

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

In Question C if input is 7 1 1 1 2 2 2 2 the max clifs possible if 3 while program will give 1

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

My Solution of E2 (and E1 as well)

https://codeforces.me/contest/1537/submission/120335720

I greedily pick the best prefix. Though I read the editorial for this problem I am not sure why the code implementation was so long.

PS: MY PURPOSE OF POSTING THE CODE LINK IS THAT MAYBE SOMEONE CAN PINPOINT IF I HAVE WRONG LOGIC OR CODE AS other COMMENTS MENTION WEAK TEST CASES FOR THE PROBLEM.

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

For E2 :

Let's say we have three pointers A, B, and C. Where C represents the best prefix of the string which when repeated and then shaved off from the end to reach a length k would give the correct answer. A is the pointer in the best string, that we have found until now, and B is the pointer to the current character in the string we need to compare with A.

Now, let's start with A = 0, and C = 0, and B = 1, which means that a string containing only the first element is the best answer until now, and we need to compare s[A], and s[B] now.

There can be three conditions:

  1. $$$s[A] < s[B]$$$ : In this case, since the newer character is more than the first element, we should reject it. Why? Let's say we have "dbcae", when you have A=0, and B=4. Now in this case 'd'<'e', so we will reject 'e' and declare the current best as the answer, which in this case would be "dbca". Now, if we repeat it, let's say for k=8, then it would become "dbcadbca". But in the case, we took in the 'e', it would be "dbcaedbc", which is lexicographically bigger. So no matter if anything smaller than this is present in the string, the answer can not be made better. So we end our loop here, and just print the answer.

  2. $$$s[A] > s[B]$$$ : In this case, the newer character is actually better than the original character. So the answer is actually better off using the newer longer string, instead of the older one. So in this case, C is set to B (the new best), A is reset to zero, and B is increased by one.

  3. $$$s[A]==s[B]$$$ : In this case, we don't know whether we are going to get something better, or not. So if we have "dbcbdbca", and A=0,B=4,C=3 then you have s[A]=s[B]. Now this repetition can actually lead to something that is better than repeating the original answer. Like for example, if we move forward, s[3]>s[7], which means that C=7 is the correct answer,instead of C=3. As "dbcbdbca" is better than "dbcbdbcb" (if k=8). So in this case, we just simply increase A, and B. Just a little corner case though : if A has reached C (the former best), it would mean that the original string has just repeated itself, then there is nothing more to compare. The B value is actually a better choice, so C=B, A=0 and B++ is done.

This loop is followed until B reaches n.

Here is a submission using this approach : submission

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

I am unable to figure out the issue with my problem F submission. I am simply following 3 steps:

if the summation of the difference is odd -> "NO"
else if (not bipartite graph) || (sumOfDifference(color-0) - sumOfDifference(color-1)) == 0 -> "YES"
else "NO"

I am trying to find the bug for the last 2 hours but no luck so far. Please help.

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

Problem D is really amazing and its tutorial is great!

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

I know I'm late on this, but I just noticed that problem D is identical to a problem from the MIT Primes 2019 G5: https://math.mit.edu/research/highschool/primes/materials/2019/entpro19.pdf.

I know that doesn't mean much since the problem statement is generic enough to show up in multiple locations, but it's something interesting to say the least :D

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

Intuition behind problem F:

Think of three nodes in a graph which have edges between them a -> b -> c.

Now consider how we can manipulate values,

  1. One way to manipulate values is to apply +1/-1 to only (a, b) or (b, c).
  2. We can apply -1 to (a, b) and then +1 to (b, c). What does this do? This effectively make (a, b, c) = (a — 1, b, c + 1) [We effectively transferred 1 from a to c). Now realise that we can "transfer" values from one node to any another node which is at even distance from it in this manner.

So now mentally divide the points into two groups A and B, such that each node in a group is at odd distance from all the other points in that group. This is nothing but a bipartite graph.

So (1) basically allows to increase the total values of both A and B by any common value and (2) basically allows us to rearrange values however we like in one group of nodes in bipartite graph.

So if the graph is two-colorable, just check if the total delta between actual and required values is equal in both A and B. If the graph is not two colorable, that means we can also rearrange values between A and B => just check if total delta between actual and required values is even. (Since we can only change total delta by 2 * x at any operation.)