AmShZ's blog

By AmShZ, 2 years ago, In English

Hi Codeforces!

Keshi, alireza_kaviani and I are delighted to invite you to participate in Codeforces Round 800 (Div. 1) and Codeforces Round 800 (Div. 2).

  • Start time: Jun/16/2022 17:35 (Moscow time)
  • Duration: $$$120$$$ minutes
  • Number of Tasks: $$$6$$$ for both divisions
  • Rated range: ($$$-\infty$$$,$$$1899$$$] for Div2, [$$$1900$$$, $$$\infty$$$) for Div1

We are honored to have set the 800th Codeforces round. We wish this wonderful platform all the best along with many other exciting rounds.

Huge thanks to the following people:

Thanks to NEAR for supporting this round, details can be found in this post.

We have worked hard to keep the statements clean and the pretests strong!

Please read all of the problems and their notes, enjoy your time and solve as many as you can! Good luck have fun to everyone!

The scoring distributions will be announced later.

UPD: Here are the scoring distributions:

  • Div. 1: 750 1000 1500 2250 2500 3000

  • Div. 2: 500 1000 1500 1750 2250 3000

UPD: Editorial is out!

  • Vote: I like it
  • +796
  • Vote: I do not like it

| Write comment?
»
2 years ago, # |
  Vote: I like it +61 Vote: I do not like it

Great contest! you will enjoy it.

  • »
    »
    2 years ago, # ^ |
    Rev. 2   Vote: I like it -35 Vote: I do not like it

    lol .. He said Huge thanks to testers for providing invaluable feedback.

    If you dont believe me scroll and check.

»
2 years ago, # |
  Vote: I like it -9 Vote: I do not like it

Orz

»
2 years ago, # |
  Vote: I like it +11 Vote: I do not like it

Yet another great Iranian round :) orz

»
2 years ago, # |
  Vote: I like it +29 Vote: I do not like it

Hope everyone can be red in this contest (of course include me).

»
2 years ago, # |
  Vote: I like it +63 Vote: I do not like it

btw congrats to alireza_kaviani for qualifying in Iran's IOI 2022 team

»
2 years ago, # |
  Vote: I like it +23 Vote: I do not like it

Codeforces orz
MikeMirzayanov orz
Polygon orz

»
2 years ago, # |
  Vote: I like it +17 Vote: I do not like it

Orz

»
2 years ago, # |
  Vote: I like it +15 Vote: I do not like it

Paranoid creepy tasks?

  • »
    »
    2 years ago, # ^ |
      Vote: I like it +36 Vote: I do not like it

    Don't worry, no surprises.

    • »
      »
      »
      2 years ago, # ^ |
        Vote: I like it -21 Vote: I do not like it

      Don't worry, there will be no more than $$$10^9+7$$$ suprises.

»
2 years ago, # |
  Vote: I like it +64 Vote: I do not like it

As a tester, problems are great and statements are short.

I encourage you to participate in this round!

You will definitely enjoy this round!

  • »
    »
    2 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    Haha certainly....but sometimes short ones are the real fire ones...looking forward for this round....

»
2 years ago, # |
Rev. 3   Vote: I like it +7 Vote: I do not like it

Where is translation into russian?

»
2 years ago, # |
  Vote: I like it +15 Vote: I do not like it

Another div1 with trygub support? It will be fine.

»
2 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Hope all the best for everyone

»
2 years ago, # |
  Vote: I like it +50 Vote: I do not like it

Finally, my first Div 1 contest. Yayyyy. Every time I used to fall back to expert just before Div 1 contests.

»
2 years ago, # |
  Vote: I like it +13 Vote: I do not like it

Good luck for everyone!!!

»
2 years ago, # |
  Vote: I like it +10 Vote: I do not like it

good luck for everyone

»
2 years ago, # |
Rev. 4   Vote: I like it -29 Vote: I do not like it

good luck man!

»
2 years ago, # |
Rev. 4   Vote: I like it 0 Vote: I do not like it

Good luck !?

Naah,it won't help :(

»
2 years ago, # |
  Vote: I like it +9 Vote: I do not like it

800th round! A great number

»
2 years ago, # |
  Vote: I like it +8 Vote: I do not like it

My first time participating in Div. 1, I am so nervous.

  • »
    »
    2 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    how you became expert in your first contest itself??

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

      I thought the base score was 1,500, and I got +167 in my first contest.

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Wow, great!! 800 contests, its huge!! Thank you Codeforces❤️

»
2 years ago, # |
  Vote: I like it +8 Vote: I do not like it

I know I won't be able to solve any one of em, still gonna participate..

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

GAP

»
2 years ago, # |
  Vote: I like it +2 Vote: I do not like it

Hope I don't go back to being a pupil :/

»
2 years ago, # |
Rev. 2   Vote: I like it +69 Vote: I do not like it

When someone says orz as a comment
68e3682b065c5b4a66b64c2e78865293

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

tell newbie what is orz

»
2 years ago, # |
  Vote: I like it +8 Vote: I do not like it

is it contest?

»
2 years ago, # |
  Vote: I like it +33 Vote: I do not like it

I guarantee you will enjoy the contest.

»
2 years ago, # |
  Vote: I like it +23 Vote: I do not like it

I hope I don't lose points in this game.

»
2 years ago, # |
  Vote: I like it +33 Vote: I do not like it

No offence but why does authors tend to hide the score distribution and reveal it just before the contest starts?

strategy?
»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Lmao, what does +inf & -inf rating mean !!

  • »
    »
    2 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    infinity, quite literally. If you did not know, negative ratings exist and they are not rated in most rounds (most rounds' rated range begin from 0)

»
2 years ago, # |
Rev. 2   Vote: I like it +6 Vote: I do not like it

[1900, tourist] for Div1* :v

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

Good luck for everyone!!!

»
2 years ago, # |
  Vote: I like it -8 Vote: I do not like it

Why only two div2 testers?

»
2 years ago, # |
  Vote: I like it +65 Vote: I do not like it

»
2 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Why so many orz comments? Could someone explain, please?

»
2 years ago, # |
  Vote: I like it +5 Vote: I do not like it

RIP Score distributions.

»
2 years ago, # |
  Vote: I like it +4 Vote: I do not like it

When will be the score distribution update? It's just 1 hour 12 minute remaining.

»
2 years ago, # |
  Vote: I like it +15 Vote: I do not like it
waiting for score distribution be like
»
2 years ago, # |
  Vote: I like it +4 Vote: I do not like it

My first contest!!

»
2 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Not a Doctor Still doing a lot of operations.

Won't say bad round. I liked the Problems though.

»
2 years ago, # |
Rev. 2   Vote: I like it -54 Vote: I do not like it

I think that this contest isn't good. I can't understand the problems well.

  • »
    »
    2 years ago, # ^ |
      Vote: I like it -14 Vote: I do not like it

    Why so many downvotes !? It's my personal opinion !

    • »
      »
      »
      2 years ago, # ^ |
        Vote: I like it +9 Vote: I do not like it

      Because people didn't like your opinion. I mean that is how this system works. If people don't like your opinion they downvote you. if they like it then they upvote you.

»
2 years ago, # |
  Vote: I like it +12 Vote: I do not like it

If this was a Div2 I am a refrigerator. tf.

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I don't mind difficult problems but a,b,c are very observation based and took me a lot of time, hence we don't get enough time for interesting problems like D

»
2 years ago, # |
  Vote: I like it +35 Vote: I do not like it

I dont like this round (my opinion)

  • »
    »
    2 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I respect the work of autors. Its very cool to do problems for codeforces round. I dont like this types problem. Thats what I meant.

»
2 years ago, # |
  Vote: I like it +2 Vote: I do not like it

I guess I am just dumb.

»
2 years ago, # |
  Vote: I like it +10 Vote: I do not like it

Round #800 CLASSIC GREEDY ONE !!!!!!

»
2 years ago, # |
  Vote: I like it +6 Vote: I do not like it

I didn't expect adhoc tasks :(

»
2 years ago, # |
  Vote: I like it +12 Vote: I do not like it

I liked problem C. Sample cases were very useful for solving.

  • »
    »
    2 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I hated it for that reason, but problem was very good . They should'n have provided the 5th sample it was easy to guess then.

»
2 years ago, # |
  Vote: I like it -30 Vote: I do not like it

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

»
2 years ago, # |
  Vote: I like it +37 Vote: I do not like it

How to solve Div 1C?

  • »
    »
    2 years ago, # ^ |
    Rev. 4   Vote: I like it +25 Vote: I do not like it

    Reverse the graph and then do something very similar to dijstrak starting from n-1. Notice that at some node, you have a bunch of nodes you can go to and if you know their distances, you can kill some in descending order(so like their effective distance is +0 +1, +2 +3....) and find the optimum of that. Thus, what you can do is to store the current estimates incoming (after reversing) for each node and pick the best (similar to dijstrak) after adding some weights. Then, we process the nodes by current estimate similar to dijstrak. But this may potentially force you to reupdate the whole set everytime you process a node. But, you realise that you only add numbers greater than numbers you add before (since you process nodes in ascending estimates). So, you can just store the best estimate.

    Essentially its just do dijstrak with the following modification: dist[v] = min(dist[v], dist[u] + indeg[v]) indeg[v]--

    Spoiler
»
2 years ago, # |
Rev. 2   Vote: I like it +18 Vote: I do not like it

For problem D: if the sequence is decinc, there are only at most $$$3$$$ representations of it, that are of interest. For maximum increasing subsequence, you must use all elements except maybe one and if you don't use an element in the increasing sequence, it's always either first or last element.

Note that if the sequence is decinc, then so is all of its subsequences, hence you could kind of make a binary search for each $$$L$$$ on the largest $$$R$$$ such that $$$[L; R)$$$ is decinc.

But my solution failed pretests because it uses binary lifting and needs $$$O(n \log n)$$$ memory. I'm pissed off it doesn't pass.

Now that I think of it, you can probably also do it in $$$O(n)$$$ with two pointers?

»
2 years ago, # |
  Vote: I like it +58 Vote: I do not like it

I've seen a version of Div1D with answering for whole sequence in a few Polish competitions, so the key observation (that we can build the answer greedily) was known to me (I'm not saying that the rest is correct, last rounds weren't generous for me).

  • »
    »
    2 years ago, # ^ |
      Vote: I like it +65 Vote: I do not like it

    I can write a bit more: assume that we've split the prefix into two sequences (decreasing and increasing) and the next two elements are $$$x$$$ and $$$y$$$, where $$$x$$$ can be appended both to increasing and to decreasing sequence. It turns out, that if $$$x<y$$$, it's optimal to append $$$x$$$ to increasing one. If $$$x>y$$$, it's optimal to append $$$x$$$ to decreasing one.

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Approach for Div2C??

  • »
    »
    2 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    Beginning from last non-zero element, iterating backwards, keep adding arr[i], sum must never be >=0, except at Oth element. That was the opeartion about.

    • »
      »
      »
      2 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      i was iterating from backwards and decreasing the current element say a[j](initial array) by k such that it gets equal to m[j](given array) and adding k-1 to a[j-1] lastly i check that array is equal or not alongwith my pointer is on the first element or not this approach is giving wrong answer

  • »
    »
    2 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    let j = position of last non-zero number (1-indexed)

    There must be no prefix sum of length i(0<i<j) with sum <= 0

    A[j] must be negative and total sum of array A = 0

»
2 years ago, # |
  Vote: I like it +24 Vote: I do not like it

Div2B was hard -_-

»
2 years ago, # |
  Vote: I like it +3 Vote: I do not like it

I'll suffer from PTSD from now on for string problems :(

»
2 years ago, # |
  Vote: I like it +17 Vote: I do not like it

what's the solution for div1A? I have no idea why I got AC

  • »
    »
    2 years ago, # ^ |
    Rev. 2   Vote: I like it +3 Vote: I do not like it

    Hey, Can I ask you, As a div 1 participant how was Div1B?

    • »
      »
      »
      2 years ago, # ^ |
        Vote: I like it +12 Vote: I do not like it

      actually pretty simple problem on dp on trees

      • »
        »
        »
        »
        2 years ago, # ^ |
          Vote: I like it +3 Vote: I do not like it

        Can you please explain your solution, or suggest some similar dp on trees problems.

  • »
    »
    2 years ago, # ^ |
    Rev. 2   Vote: I like it +5 Vote: I do not like it

    I don't know if i am eligible to explain something to CM, but this is how I solved.

    • First I observed that if the first element = x, then we go right x times from first element.
    • If we go x times right from first then we must go left x times from second element.
    • since the second element = a[1] = ( number of rights from second — number of lefts from second). So we get right_times[1] = a[1] + x.
    • Similary construct for all indices. If any of them is negative then its not possible since we cant go negative number of times in some direction.
    • This is my code

    PS: We also need to check if at some point right[i] becomes zero then all the array elements from that index must be zero, since we dont move towards right anymore.

    • »
      »
      »
      2 years ago, # ^ |
        Vote: I like it +11 Vote: I do not like it

      oh, I understood, thanks! not bad problem though

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

tox1c_kid got trolled

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

Do you have a small test case that fails this simple and wrong solution for 1E?

  • For each element, count how distinct values on the left that the smaller than the element
  • For each element, count how distinct values on the right that the smaller than the element
  • Take the sum of the minimum of the two counts for each element
  • »
    »
    2 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    I also had the same idea, but here is the problem: It might be better to take the right maximum and then the left maximum afterwards.

    test case:

    5

    4 3 5 1 2

    The min for 4, 3, 1, 2 is clearly 1. But the min for the 5 would be 3. However, we can take right maximum and then left: 5 -> 2 -> 0. So answer is actually 1+1+2+1+1 = 6 instead of 7.

»
2 years ago, # |
  Vote: I like it +172 Vote: I do not like it

1693C - Keshi in Search of AmShZ is the problem of the year.

  • »
    »
    2 years ago, # ^ |
      Vote: I like it +39 Vote: I do not like it

    Disagree, C was standard imo, for example 102341H - Hypno is very similar, but a bit harder.

    D, E and F were rather nice, a bit of AtCoderForces spirit, but still way better than most AGCs.

    • »
      »
      »
      2 years ago, # ^ |
        Vote: I like it +29 Vote: I do not like it

      My bad, I had never seen anything similar to C.

      • »
        »
        »
        »
        2 years ago, # ^ |
          Vote: I like it +49 Vote: I do not like it

        Nope, not your bad, it's just your opinion versus mine. The fact that for you it was good and interesting can only be a plus for the problem. :P

    • »
      »
      »
      2 years ago, # ^ |
        Vote: I like it +26 Vote: I do not like it

      wow, it's an honor.

»
2 years ago, # |
  Vote: I like it +20 Vote: I do not like it

Problems were interesting.

»
2 years ago, # |
Rev. 4   Vote: I like it 0 Vote: I do not like it

So hard..... I can not solve (Div 1. C)1693C - Keshi in Search of AmShZ, I thought topological sorting + DP may work, but what if the graph has a loop and is not a DAG?`

`

  • »
    »
    2 years ago, # ^ |
    Rev. 4   Vote: I like it 0 Vote: I do not like it

    you run a djikstra-like algorithm on the reversed graph. In each iteration, my solution has an invariant that the nodes that have been popped from the set have the smallest values of $$$dp[u]$$$, where $$$dp[u]$$$ is the minimal cost required if one starts from node $$$u$$$ and goes to node $$$n$$$. We remove edges only when we are at the node from which the edge emanates (goes out). Then you can see how a djikstra-like algorithm always maintains this invariant, and hence answer is $$$dp[1]$$$.

    details: 160892338

    • »
      »
      »
      2 years ago, # ^ |
        Vote: I like it -6 Vote: I do not like it

      I appreciate it, I think I do not understand the idea of djikstra totally, it is time to take my DS book up again.

      Sadly, I may get a down rank.

»
2 years ago, # |
Rev. 2   Vote: I like it +62 Vote: I do not like it

D1C is amazing and suitable for commemorable 800th round, thanks!

hint
»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I hope to reach expert next round :( :(

»
2 years ago, # |
  Vote: I like it +37 Vote: I do not like it

rainboy orz on astonishing participation! He won't become a GM after this contest but he really deserved it. This strategy of solving the problems starting with the harder ones is really not that bad, especially for educational purposes.

»
2 years ago, # |
  Vote: I like it +11 Vote: I do not like it

The best round recently I think! Thank the author!

»
2 years ago, # |
  Vote: I like it +12 Vote: I do not like it

small feedback: A is kinda cool, B&C both too standart IMO

»
2 years ago, # |
  Vote: I like it +9 Vote: I do not like it

Not sure about the complexity of "dive" function in my solution to D: 160848374. If anybody wants to try to create the test were the complexity is worse, you're welcome (don't know if it's correct or not).

  • »
    »
    2 years ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

    I think I did the same thing, guessing that it would work (somehow it did). I would also like to see a proof of why this type of memoization runs in linear time.

    • »
      »
      »
      2 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Yeah. I’m doing more stuff, but I can believe that the transition is correct.

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

I am able to solve only problem A.

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

    Glad to see your persistence, try our best to prepare for the next round!

»
2 years ago, # |
Rev. 3   Vote: I like it -11 Vote: I do not like it

see https://codeforces.net/blog/entry/103952?#comment-923384

UPD: why downvotes ? I simply removed my original post

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

is "wrong answer jury had better answer" different from "wrong answer expected ,found"?

  • »
    »
    2 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    It's 2 different types of problems: "jury" thingy appears where you have to calculate a minimum or maximum answer for example and at some point there is a possibility to have a better answer than yours, but "expected" simply stands for a wrong answer.

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Thanks for the round, Div1 pC was really interesting!

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

What was the sol for Div2 C?

  • »
    »
    2 years ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

    I solved this problem using RBS (Regular Bracket Sequence) pattern. If you consider the positive numbers as the number of open brackets and the negative numbers as the number of closing brackets, you will see "If the total sequence is regular and it's closed then the answer is yes".

    So you will get Yes for ( ()()() ) or ((())) or ( ( () ((())) ) ). But if the bracket is like this ()()() then it's no because in this case you can't get back to the first index.

  • »
    »
    2 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    If at any index < last index prefix sum is <= 0 || total sum != 0 then ans is no

    here last index is index of last non zero element.

    Take care of few edge cases such as all zero elements

»
2 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Great contest. The problemset was amazing and so fun to solve. Enjoyed this contest so much.

»
2 years ago, # |
  Vote: I like it +10 Vote: I do not like it

I think the problem setter is a Radiohead fan. Some of the problem title is similar to Radiohead's song title . Or its just a coincidence .

»
2 years ago, # |
  Vote: I like it +9 Vote: I do not like it

very good and balanced round + interesting problems. Though I FSTed on div2c but was a silly mistake.

Overall thanks for the amazing round

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

How to solve Div2 D problem?

  • »
    »
    2 years ago, # ^ |
    Rev. 3   Vote: I like it +7 Vote: I do not like it

    do DFS on the tree.

    if the node children returned a number which is greater than or equal lv, just return the min of the returned value of the children and the rv

    if it is less than the lv, you need to make another operation to fix this issue, so you will increase sol by one, then you will need to return rv.

    • »
      »
      »
      2 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      But how do you prove that the configurations doesn't matter?

      In the sense , say a node has value 5.. 5 can be written as [1,1,3] , [1,2,2] and so on. But in your solution , you just see the min(sum, Ri).

      Why does your solution work? Proof?

      • »
        »
        »
        »
        2 years ago, # ^ |
        Rev. 3   Vote: I like it +1 Vote: I do not like it

        I can't understand what you mean by configuration and why there are 3 numbers in your examples.

        I am not good at writing formal mathematical proofs, but I will try to proof it logically.

        The current node doesn't care how many nodes under it, it only cares about the maximum value they all need, because it is the maximum value I can give to the current node, I can decrease it if I want, but I cannot increase it without an additional operation.

        But notice that the sum of all the child nodes values may be greater than Rv, so I take the min of them

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anyone tell the testcase for which my submission is failing (Div2C):- Submission

»
2 years ago, # |
  Vote: I like it +8 Vote: I do not like it

luck maatters much in life

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

can someone tell me why i got tle'd in this submission https://codeforces.net/contest/1694/submission/160921292 Thank you