15

Codeforces Round #726 (Div.2) Editorial

 2 years ago
source link: http://codeforces.com/blog/entry/91381
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Codeforces Round #726 (Div.2) Editorial
By ssense, history, 6 months ago, In English

5 months ago, # |

This was faster than the system testing!

Thank you!

  • 5 months ago, # ^ |

    The comment is hidden because of too negative feedback, click here to view it
    • 5 months ago, # ^ |

      Can you AC mathforces and adhocforces without writing Code?

      • 5 months ago, # ^ |

        destroyed in seconds xd

      • 5 months ago, # ^ |

        noice

      • 5 months ago, # ^ |

        math kills me

      • 5 months ago, # ^ |

        We can then have another coding language Mathular/ Adhocular for this website.

      • 5 months ago, # ^ |

        top 10 responses that led to suicides XD

5 months ago, # |

Rev. 5  

-316

The comment is hidden because of too negative feedback, click here to view it
  • 5 months ago, # ^ |

    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.

    • 5 months ago, # ^ |

      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?

      • 5 months ago, # ^ |

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

  • 5 months ago, # ^ |

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

    • 5 months ago, # ^ |

      monogon coordination could use improvement, needs some time before can take over cf :(

    • 5 months ago, # ^ |

      Rev. 2  

      +9

      weak pretests is not a problem for problem E ,because if we get the correct logic it will automatically pass. As it is not a math question no need to depend on pretests. Btw contest is really nice.

      • 5 months ago, # ^ |

        Yes bro, totally agree with you.

    • 5 months ago, # ^ |

      I used suffix array and failed system test miserably. Should have think about the special case more carefully. Interesting problems anyway. RIP my rating.

      • 5 months ago, # ^ |

  • 5 months ago, # ^ |

    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.

    • 5 months ago, # ^ |

      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.

  • 5 months ago, # ^ |

    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

5 months ago, # |

Rev. 2  

+18

Adhoc Adhoc everywhere :0

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

5 months ago, # |

Rev. 7  

-30

The comment is hidden because of too negative feedback, click here to view it

5 months ago, # |

The comment is hidden because of too negative feedback, click here to view it

5 months ago, # |

How accepted solutions for problem E1 rose so quickly ?

    • 5 months ago, # ^ |

      Rev. 3  

      +17

      This is horrible :(

      Everyone should report the channel now!

    • 5 months ago, # ^ |

      I hope the moss checker catches them.

    • 5 months ago, # ^ |

      I am relatively new to CF. Any idea what is going to happen? Will the round get unrated or is the plag checker capable enough to remove any plag solutions?

      • 5 months ago, # ^ |

        Plag checker usually removes people from rankings

    • 5 months ago, # ^ |

      nah man D was on gfg also, I think that's also a major reason

    • 5 months ago, # ^ |

      I was wondering the same about the submission for Problem D. I was trying to crack the pattern but couldn't.

      This guy's an Indian judging by the Hashtags he has put in videos. There's a lot of cheating nowadays going on atleast involving Indians. Platforms like Codechef have become worthless because of these people.

    • 5 months ago, # ^ |

      Please delete this comment as more people are getting to know about this channel

  • 5 months ago, # ^ |

    Hey, there are many telegram grps exist where they post solutions till E2.

5 months ago, # |

No original problems, just dumb adhoc problems

5 months ago, # |

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

There seems to be no guarantee of this condition.

  • 5 months ago, # ^ |

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

5 months ago, # |

Rev. 2  

+197

In problem E, one can prove that

So just compare the prefixes using Z function.

  • 5 months ago, # ^ |

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

    • 5 months ago, # ^ |

      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 ,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 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 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,,so , we need to cut it.

  • 5 months ago, # ^ |

    Catch Jiangly and ORZ%

  • 5 months ago, # ^ |

    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?

    • 5 months ago, # ^ |

      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.

    • 5 months ago, # ^ |

      Will you please provide the proof for the above relation?

    • 5 months ago, # ^ |

      I'm a bit late, but here is some more or less intuitive proof. We can look at strings as base-p numbers (here , but it doesn't really matter). Obviously it's enough to compare string consisting of copies of with string consisting of copies of . In other words, we want to compare

      And the last line is just vs (here is concatenation)

      • 5 months ago, # ^ |

        I cannot understand what do you mean by in the summation formula. Can you please elaborate more?

        • 5 months ago, # ^ |

          To concatenate numbers you need to multiply one of them by some power of base. For example, if and , then , and

          • 5 months ago, # ^ |

            Wow, amazing way to see strings. Thank you very much.

      • 4 months ago, # ^ |

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

    • 5 months ago, # ^ |

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

5 months ago, # |

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 :)

  • 5 months ago, # ^ |

    What did you do? How did you simulate each number? I believe you need to know the optimal move, but if you know that then you actually know the answer

    • 5 months ago, # ^ |

      Rev. 2  

      +2

      I used dp to calculate the answer.

      Let dp[i] = 1, if alice can win when n=i,

      Simply, for any j which divide i,

      If dp[i-j] is 0 then, dp[i] is 1.

      I used this method to find answer for 100 natural numbers, then I guessed the sequence.

      • 5 months ago, # ^ |

        so you became master after all!!! gib tips

      • 5 months ago, # ^ |

        Got it, thanks

      • 5 months ago, # ^ |

        Rev. 2  

        0

        can you explain it further ?

      • 5 months ago, # ^ |

        ohh gr8

  • 5 months ago, # ^ |

    Now you're orange. Congrats

  • 5 months ago, # ^ |

    Rev. 2  

    0

    Were you familiar that these type of questions are pattern finding or did you first try to approach the question using paper and pencil before brute force.

    • 5 months ago, # ^ |

      Generally (most of which I encountered), game theory questions can be guessed by writing the answer for some initial numbers.

      • 5 months ago, # ^ |

        thank you.

  • 5 months ago, # ^ |

    heres the code https://ideone.com/kNqcuK to print answers for first 1000 numbers

  • 5 months ago, # ^ |

    same))

5 months ago, # |

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

5 months ago, # |

Woow !! fast editorial Thanks :)

5 months ago, # |

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

  • 5 months ago, # ^ |

    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

  • 5 months ago, # ^ |

    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!!.

    • 5 months ago, # ^ |

      yes I got it, thanks!

      • 5 months ago, # ^ |

        welcome bro!

5 months ago, # |

Thanks for editorial.

5 months ago, # |

The problemset was fairly interesting.

5 months ago, # |

Rev. 4  

+61

Check out my simple greedy solution for E2. 119887467

Explanation and Code
  • 5 months ago, # ^ |

    Can you please explain the else if statement?

    • 5 months ago, # ^ |

      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 :)

      • 5 months ago, # ^ |

        How did you come up with this idea ?? Is there some algorithm or practice?

        • 5 months ago, # ^ |

          I simply followed the greedy approach to get the lexicographically smallest string. But, some people are talking about some Z function, I have no idea about it.

  • 5 months ago, # ^ |

    Underrated

  • 5 months ago, # ^ |

    Very clean soltuion!

  • 5 months ago, # ^ |

    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

  • 5 months ago, # ^ |

    nice solution

  • 5 months ago, # ^ |

    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

    • 5 months ago, # ^ |

      Yeah, you are right, there is no need to take the modulo.

  • 5 months ago, # ^ |

    I had this same solution but since no one mentioned it I thought I am missing something but couldn`t find anything wrong with it. Now I can rest.

  • 5 months ago, # ^ |

    Great Solution! Learned Z function for this problem, but couldn't understand the tutorial. Finally found this solution. Piece of cake:)

  • 4 months ago, # ^ |

    I just wanna say this is an brilliant solution

5 months ago, # |

Thx for great contest and editorial!

5 months ago, # |

Problem statement was quite clear.awasome explanation.

5 months ago, # |

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

5 months ago, # |

E1 Test 43 should have been a pretest.

5 months ago, # |

It was fun doing this contest, and yes this is codeforces .

5 months ago, # |

Problem D is amazing!

5 months ago, # |

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 to . Let the current optimal length of prefix be .

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

If (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 , it is more optimal to extend our prefix up to this point; hence we do it, i.e. set our optimal prefix length to . This needs some more explanation, so bear with me for the next couple of lines.

There’s also the more interesting case of , 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 ; both are equal. How? Well, we break when , and in case of , we simply extend our prefix up to here, making it equal.

Let’s deal with the 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 , 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 , 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 , and becomes unequal at index ; hence extending our prefix length simply means changing the prefix to .

This helps us maintain an solution. 119889474

  • 5 months ago, # ^ |

    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?

    • 5 months ago, # ^ |

      Rev. 2  

      +7

      Thank you for pointing this out. I believe my write-up is still incomplete, and the case requires another explanation. Let me rewrite this particular case.

      When , 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.

      • 5 months ago, # ^ |

        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.

        • 5 months ago, # ^ |

          Can you please prove or explain these two things:

          1. From the third paragraph, "Hence, we are simply left with proving that 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 , we also need to check further by comparing the string starting at the third with the string

          2. From the last paragraph, "This means there exists an where . 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 (0-based indexing), we can repeat the prefix of length . However when , I couldn't find any prefix of to repeat that yields a more optimal answer.

5 months ago, # |

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!

  • 5 months ago, # ^ |

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

    • 5 months ago, # ^ |

      or just use INT_MAX

      • 5 months ago, # ^ |

        Accepted! Thank You

    • 5 months ago, # ^ |

      Thanks Got it!

  • 5 months ago, # ^ |

    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

5 months ago, # |

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

5 months ago, # |

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

  • 5 months ago, # ^ |

    Rev. 2  

    0

    The exact same thing happened with me. I even switched to Python to code it up quicker, but I just missed the deadline. :(

5 months ago, # |

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?

  • 5 months ago, # ^ |

    What does mk mean?

    • 5 months ago, # ^ |

      Height of the kth mountain

5 months ago, # |

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

  • 5 months ago, # ^ |

    Don't worry mike will kick out the cheaters by tomorrow.

5 months ago, # |

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.

  • 5 months ago, # ^ |

    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.

    • 5 months ago, # ^ |

      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.

    • 7 weeks ago, # ^ |

      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.

      • 7 weeks ago, # ^ |

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

        • 7 weeks ago, # ^ |

          Ops.I thought otherwise.Thanks for the reply.

5 months ago, # |

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

5 months ago, # |

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

  • 5 months ago, # ^ |

    The comment is hidden because of too negative feedback, click here to view it
    • 5 months ago, # ^ |

      such a binary person

  • 4 months ago, # ^ |

    update :

    NO action taken yet :)

5 months ago, # |

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.

  • 5 months ago, # ^ |

    119900135 one of my friends solution.

    • 5 months ago, # ^ |

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

      • 5 months ago, # ^ |

        Can you explain your binary search based solution please?

        • 5 months ago, # ^ |

          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.

          • 5 months ago, # ^ |

            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"

            • 5 months ago, # ^ |

              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.

5 months ago, # |

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

  • 5 months ago, # ^ |

    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.

    • 5 months ago, # ^ |

      Yeah, understood it. Thanks :')

    • 5 months ago, # ^ |

      can you pls explain why this condition always holds "so n-D, cannot be in the form of 2^K." ?

      • 5 months ago, # ^ |

        Rev. 2  

        0

        Numbers in the form of 2^k have only even divisors, but here, a number n has an odd divisor D.

        • 5 months ago, # ^ |

          yeah, you are right. if number is in the form of 2^k for ex — 2*2*2 then all factors have to be even. thank you!!!

5 months ago, # |

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

5 months ago, # |

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

5 months ago, # |

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.com/contest/1537/submission/119930955

5 months ago, # |

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

It'd produce , which is not what is described in the tutorial.

Or have I misunderstood anything?

5 months ago, # |

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

5 months ago, # |

System testing was slower than internet Explorer. XD!

5 months ago, # |

Problem F is nice.

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

5 months ago, # |

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

5 months ago, # |

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 :))

5 months ago, # |

What if in the first question the array consists of -10000 five times and sum we get is -50000. So we have to add +10000 five times and then one more to make it divsible by current size of array. In question, the constraint given to the inputs of array was -10000 <= A[i] <= 10000. Am i correct or something is there which I am not getting?

  • 5 months ago, # ^ |

    I did the same mistake during the contest, the problem states that we can add any non-negative integer so if sum < n we will always print 1

5 months ago, # |

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

  • 5 months ago, # ^ |

    Loved your solution

5 months ago, # |

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

5 months ago, # |

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.

  • 5 months ago, # ^ |

    Extra points for the first six contests.

5 months ago, # |

My Simple greedy Solution for E2 119941150

5 months ago, # |

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 exception. I want to know the intuition behind this pattern if someone come up with it without bruteforce pattern to look.

  • 5 months ago, # ^ |

    I tried to find some strategy or some sort of invariant which Alice can use to win. I wrote as . Alice can give Bob which has all odd divisors and Alice is guaranteed to get an even number again. Now only exceptions are when or .

5 months ago, # |

Me waiting for system testing to judge my answers ... Meanwhile ssense with the lightning fast editorial ... HOLD UP ... HERE IS THE EDITORIAL :) thanx mannnn...

5 months ago, # |

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

5 months ago, # |

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

  • 5 months ago, # ^ |

    and this is giving run time error

  • 5 months ago, # ^ |

    Rev. 2  

    0

    I guess the loop where you are checking the min difference runs from 0 to n-1 because of the a[i+1].

    • 5 months ago, # ^ |

      oh thanks.i will check it!!

  • 5 months ago, # ^ |

    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];

    • 5 months ago, # ^ |

      yes i noticed that. Thanks!!

5 months ago, # |

Rev. 9  

+14

insight I used for E1/E2:

a bit long but simple

5 months ago, # |

problem D was same as this leetcode problem: link

  • 5 months ago, # ^ |

    But LeetCode problem gives , whereas the Codeforces edition has . This makes the problem drastically harder because a naive memoization/recursion will work on the LeetCode, but not the Codeforces rendition.

5 months ago, # |

In problems like D — Deleting Divisors, how to spot these patterns of even, odd, power of 2? I could only write a brute force code which was (obviously) giving TLE. So how to spot these patterns in future problems?

5 months ago, # |

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.com/contest/1537/submission/119930117)

    • 5 months ago, # ^ |

      thnx man, that helped me. The problem was actually in the lps function.

      • 5 months ago, # ^ |

        I'm glad that it helped!

5 months ago, # |

I think there is a typo for problem D code, cout << mn << "\n"; where does mn come from?

5 months ago, # |

Rev. 4  

+3

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

Let it be,

Now we can reduce until it becomes some or .

Then possible moves players can make are: for some in prime factorisation of .

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.com/contest/1537/submission/119883715

  • 5 months ago, # ^ |

    That's a nice approach to the problem. But as is even , we only need to check power of . For an odd number of moves either must have an odd divisor or power of must be even. I think this then reduces to the same as the editorial proof.

    • 5 months ago, # ^ |

      Yes, you are correct! Nice observation!

5 months ago, # |

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

5 months ago, # |

I don't understand proof of E1. Can someone please explain?

  • 5 months ago, # ^ |

    Same here.

    • 5 months ago, # ^ |

      Rev. 2  

      0

      it is easy to understand the ans is the prefix string of s, so we suppose current ans is , now we need compare and .

      if (pos begin at 1), then is bterr than .

      else if , is worse.

      else if , is worse,becase ,if not is better than

      My English is poor becase I am a Chinese student. Do you understand me?

      • 5 months ago, # ^ |

        Rev. 2  

        0

        No. Here, what is i+1 and a?

        • 5 months ago, # ^ |

          is the position now we count, is current answer.

      • 5 months ago, # ^ |

        I don't understand why "the ans is the prefix string of s"?

5 months ago, # |

Rev. 2  

0

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

5 months ago, # |

Rev. 2  

0

[deleted]

5 months ago, # |

This round was easy compared to previous div2 rounds

5 months ago, # |

Rev. 2  

0

I tried erase and extend easy version after reading and understanding the editorial then i coded it in python but i got tle while the same code in c++ has ac . Can someone help me to know how can the python code be optimized .

this is my solution https://codeforces.com/contest/1537/submission/119926280

5 months ago, # |

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

  • 5 months ago, # ^ |

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

    • 5 months ago, # ^ |

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

      • 5 months ago, # ^ |

        Then check for each connected component.

5 months ago, # |

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

  • 5 months ago, # ^ |

    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.

    • 5 months ago, # ^ |

      Thanks for the nice explanation!

    • 4 months ago, # ^ |

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

      • 4 months ago, # ^ |

        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.

        • 4 months ago, # ^ |

          Thanks i understood it completely.

5 months ago, # |

E1 editorial not clear. the proof part

someone help me pls

5 months ago, # |

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

5 months ago, # |

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)

5 months ago, # |

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

5 months ago, # |

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.

5 months ago, # |

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.com/contest/1537/submission/119877862

  • 5 months ago, # ^ |

    try 4 8 cacb

  • 5 months ago, # ^ |

    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

    • 5 months ago, # ^ |

      I see. Thank you !

5 months ago, # |

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 ?

5 months ago, # |

problem B so dark, bruh, lmao !

5 months ago, # |

Rev. 2  

0

import java.io.*; import java.util.*; public class MyClass { public static void main(String args[]) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); while(t-- >0) { int n=Integer.parseInt(br.readLine()); long arr[]=new long[n]; String s[]=br.readLine().split(" "); for(int i=0;i<n;i++) { arr[i]=Long.parseLong(s[i]);
} Arrays.sort(arr); StringBuilder sb=new StringBuilder(); if(n==2) { sb.append(arr[0]+" "+arr[1]); //System.out.println(arr[0]+" "+arr[1]); } else { int pos=-1; long min=Long.MAX_VALUE; for(int i=1;i<n;i++) { if(min>arr[i]-arr[i-1]) { pos=i; min=arr[i]-arr[i-1]; } }

for(int i=pos;i<n;i++)
            {
                sb.append(arr[i]+" ");
                //System.out.print(arr[i]+" ");
            }
            for(int i=0;i<pos;i++)
            {
                sb.append(arr[i]+" ");
                //System.out.print(arr[i]+" ");
            }
        }
        System.out.println(sb);
    }
}

its giving TLE on test case 60. can anyone please help me this is question number C

5 months ago, # |

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

  • 5 months ago, # ^ |

    Can you share your logic please?

5 months ago, # |

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

  • 5 months ago, # ^ |

    read the question properly its walking uphill or flat is harder than walking downhill

5 months ago, # |

Rev. 2  

0

Hi guys, I have a question in problem F: how to prove where is a sufficent condition for the answer when graph is a biparty ? The necessity is obvious but I can't prove the sufficiency. Thanks guys!

5 months ago, # |

Rev. 2  

0

//Erase and Extend (Hard Version), by two pointers

include "bits/stdc++.h"

using namespace std; int main(){ ios::sync_with_stdio(false); string str; int n, k; while(cin >> n >> k){ cin >> str; int last = 1; int first = 0; int len = 1; while(last < n && last < k){ if(str[last] > str[first]) break; if(str[last] == str[first]){ first++; last++; } else{ first = 0; last++; len = last; //save the length } } //cout << len << endl; //continue; string ans = str.substr(0, len); int cnt = k / len; int rem = k % len; while(cnt--) cout << ans; for(int i = 0; i < rem; i++) cout << ans[i]; cout << endl; } return 0; }

5 months ago, # |

Rev. 2  

0

My Solution of E2 (and E1 as well)

https://codeforces.com/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.

5 months ago, # |

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. : 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. : 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. : 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

5 months ago, # |

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.

    • 5 months ago, # ^ |

      maybe you have an issue with bipartite checking? thonk

      • 5 months ago, # ^ |

        Just now, I submitted this for this straightforward bipartite problem, and it got accepted w/o any change in logic

      • 5 months ago, # ^ |

        if(sum % 2 == 1) — issue was here. If sum is odd and negative then sum % 2 will be -1, not 1

4 months ago, # |

Problem D is really amazing and its tutorial is great!

3 months ago, # |

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

2 months ago, # |

In question C. Challenging Cliff I think there is an error. It is given that abs(h1-hn) should be minimum so it should not bother if h1 being smaller than hn be placed at the end cause the absolute difference between the both will still be the same. But if you do this, then it is showing wrong answer.

16 hours ago, # |

Rev. 2  

0

Can someone tell me why my code exceeds the time limit on test 60? For question C challenging Cliffs Thank you!! https://codeforces.com/contest/1537/submission/135963404


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK