induk_v_tsiane's blog

By induk_v_tsiane, history, 15 months ago, translation, In English

Hello, Codeforces.

We are happy to invite you to Codeforces Round 892 (Div. 2), which will take place on Aug/12/2023 17:35 (Moscow time). All of the problems are original and were prepared by a collective of authors, consisting of kristevalex, i_love_penguins, efimovpaul and me, induk_v_tsiane. This round will be rated for participants with a rating lower than 2100.

We would like to thank:

You will be given 6 problems and 2 hours to solve them. The score distribution is 500 — 1000 — 1250 — 1750 — 2250 — 3000.

I would like to also congratulate my cousin Max, who is turning 30 the day of the round. If you wish, you can write birthday wishes for him and I will pass them on.

UPD: Editorial

UPD 2: Congratulations to the winners!

Div. 2:

  1. modulo998244353

  2. botjiaxun

  3. Tmath_OneLove

  4. FengjianZhu

  5. Alihan_8

Div. 1:

  1. Geothermal

  2. heno239

  3. maspy

  4. jiangly

  5. Ormlis

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

| Write comment?
»
15 months ago, # |
Rev. 2   Vote: I like it +21 Vote: I do not like it

As a participant I hope to get 1300+ rating or even better, Specialist

Also Happy Birthday Max, sending you best wishes

  • »
    »
    15 months ago, # ^ |
      Vote: I like it +21 Vote: I do not like it

    As a participant I hope to get 1800+ rating or even better, Candidate Master

    Also Happy Birthday Max, sending you the best best best wishes

    • »
      »
      »
      15 months ago, # ^ |
        Vote: I like it +42 Vote: I do not like it

      As a participant I just hope to get rated and nothing else

      Also Happy Birthday Max, sending you best wishes

      • »
        »
        »
        »
        15 months ago, # ^ |
          Vote: I like it +22 Vote: I do not like it

        As a participant nothing worse can happen after my previous contests.

        Also happy birthday Max ! Nothing cooler then having a cousin who dedicates a cf contest to you.

        • »
          »
          »
          »
          »
          15 months ago, # ^ |
            Vote: I like it +7 Vote: I do not like it

          it can always be worse

          • »
            »
            »
            »
            »
            »
            15 months ago, # ^ |
              Vote: I like it +4 Vote: I do not like it

            As a participant I hope to get 1800+ rating or even better, Candidate Master

            Also Happy Birthday Max, sending you the best best best wishes

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

              why is everyone in this comments section pretending to care about Max's birthday?

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

                I actually do care tho

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

              As a participant I hope to get 1700+ rating or even better, Candidate Master

              Also Happy Birthday Max, sending you Best Wishes

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

          L bro, worse happened

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

            it's better than previous contest

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

    As a participant I hope to get 1525+ rating or even better, Expert.

    Also Happy Birthday Max, sending you best wishes.

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

As a tester I recommend you to take part in this beautiful round

»
15 months ago, # |
  Vote: I like it +33 Vote: I do not like it

As a tester, I can say that the tasks are cool and interesting

»
15 months ago, # |
  Vote: I like it +43 Vote: I do not like it

As a tester, I wish Max all the best on his birthday! Also, round is going to be fun, trust me ;)

p.s. имя нам улей

»
15 months ago, # |
  Vote: I like it -29 Vote: I do not like it

Is this rated? Please dont downvote. Tomorrow is my birthday.

  • »
    »
    15 months ago, # ^ |
      Vote: I like it +35 Vote: I do not like it

    This round will be rated for participants with a rating lower than 2100.

  • »
    »
    15 months ago, # ^ |
      Vote: I like it +15 Vote: I do not like it

    LOL! You were asking for downvote. Anyway, happy birthday!

»
15 months ago, # |
Rev. 2   Vote: I like it +75 Vote: I do not like it

As a tester good luck! You will need it

»
15 months ago, # |
  Vote: I like it +5 Vote: I do not like it

As not a tester good luck!

»
15 months ago, # |
Rev. 2   Vote: I like it +30 Vote: I do not like it

As "еритв" I also recommend you to participate in this round!

P.S. Имя нам улей

»
15 months ago, # |
  Vote: I like it +8 Vote: I do not like it

happy birthday Max

may i reach my Max rating in this contest

»
15 months ago, # |
  Vote: I like it +3 Vote: I do not like it

Happy birthday to bro Max

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

As a tester I recommend you to take part in this round!

»
15 months ago, # |
  Vote: I like it -9 Vote: I do not like it

Can I hope ......

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

as a tester, I can say that the round is interesting, I recommend participating

»
15 months ago, # |
  Vote: I like it +32 Vote: I do not like it

as an author, i recommend you this round!!

»
15 months ago, # |
  Vote: I like it +3 Vote: I do not like it

Feliz Cumpleanos Max!!! I express my deepest regrets for not being able to participate in the round for I am participating in the Teamscode competition which unfortunately has overlap w/ this round. :/ GL to everyone!!!

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

as someone who just saw this announcement, it might going to be a good round. GL on the round guys!

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

What is meant by “All of the problems are original” ?

»
15 months ago, # |
  Vote: I like it +3 Vote: I do not like it

Happy birthday to Max!

»
15 months ago, # |
  Vote: I like it +24 Vote: I do not like it

dori dori dori dori

»
15 months ago, # |
  Vote: I like it -48 Vote: I do not like it

As a tester, this round is mid and I don't recommend to participate.

»
15 months ago, # |
  Vote: I like it +3 Vote: I do not like it

As A participant I wish to reach Expert hopefully, and Happy 30th Birthday to Max <3

»
15 months ago, # |
  Vote: I like it +1 Vote: I do not like it

Happy Birthday Max!! Best wishes!

»
15 months ago, # |
  Vote: I like it +44 Vote: I do not like it

Happy birthday to Max!

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

how to have huge postive delta:)

»
15 months ago, # |
  Vote: I like it +14 Vote: I do not like it

A very Happy Birthday to Max.

I hope he gets Max happiness and we all get Max positive delta so that we can have Max smile on our faces after the contest and practice at our Max level to surpass our Max rating.

»
15 months ago, # |
  Vote: I like it -28 Vote: I do not like it

As a tester I recommend you to take part in this round!

  • »
    »
    15 months ago, # ^ |
      Vote: I like it +31 Vote: I do not like it

    your name doesnt appears in tester's name. how are you calling yourself a tester ?

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

As a participant I hope to get 1200+ rating or even better, Pupil

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

Thanks for this round and good luck to everyone!

»
15 months ago, # |
  Vote: I like it -14 Vote: I do not like it

as a normal person, please downvote me

»
15 months ago, # |
  Vote: I like it +5 Vote: I do not like it

Happy Birthda ,Max!

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

Happy B-day Max

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

As a participant, hoping to be pupil this time. Also Happy birthday Max best wishes from my side too.

»
15 months ago, # |
  Vote: I like it +8 Vote: I do not like it

As a participant, I hope to get a rating of 1200+ to become a pupil. Guys, please suggest ways to improve my logic-building skills.

Happy Birthday, MAX, wish you all the best in your future endeavors.

»
15 months ago, # |
  Vote: I like it +8 Vote: I do not like it

As a regular participant I hope I reach 1200+ rating...

Thanks for the round.. Looking forward to it.

»
15 months ago, # |
  Vote: I like it +8 Vote: I do not like it

As a participant, I hope to become pupil.

Also Happy Birthday Max.

»
15 months ago, # |
  Vote: I like it +8 Vote: I do not like it

Max is lucky to have a cousin like induk_v_tsiane. Happy Birthday, Max, Best wishes to you.

»
15 months ago, # |
  Vote: I like it +10 Vote: I do not like it

As a tester, I recommend everyone to participate in this round. The tasks are interesting. I wish you all good luck and positive delta.

Happy birthday, Max!

»
15 months ago, # |
  Vote: I like it +8 Vote: I do not like it

Happy birthday Max !

»
15 months ago, # |
Rev. 3   Vote: I like it +13 Vote: I do not like it

The score distribution is very nice and hope that the tasks are cool and interesting.

Also Happy Birthday Max, sending you best wishes <3

»
15 months ago, # |
  Vote: I like it +8 Vote: I do not like it

☠️☠️☠️

»
15 months ago, # |
  Vote: I like it +8 Vote: I do not like it

Happy BirthDay Max !.Wish you the best.

»
15 months ago, # |
  Vote: I like it +8 Vote: I do not like it

Happy Birthday MAX. I wish you the best. And wish me that i can reach my MAX rating by participating in this contest.

»
15 months ago, # |
  Vote: I like it +8 Vote: I do not like it

Happy birthday to MAX!

»
15 months ago, # |
  Vote: I like it +7 Vote: I do not like it

I'm hoping for a big negative delta to celebrate my birthday too(((

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

Happy Birthday, Max. Best wishes to you.

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

Hope my fever goes down so i can participate.

Also,best wishes to Max.Have a great day.

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

Hope u guys have a good "fate" round.

»
15 months ago, # |
  Vote: I like it +10 Vote: I do not like it

buru nyuu

»
15 months ago, # |
  Vote: I like it +8 Vote: I do not like it

Happy Birthday Max,sending you best wishes

»
15 months ago, # |
Rev. 2   Vote: I like it +8 Vote: I do not like it

I hope to get Candidate Master rank before the first day of my 3rd semester which will start 2 days after this round :)

And also.... happy birthday max ^_^

UPDATE: I failed :(

»
15 months ago, # |
  Vote: I like it +8 Vote: I do not like it

All the best to all my friends.....

»
15 months ago, # |
  Vote: I like it +8 Vote: I do not like it

Hope to solve 3 question in this contest.

»
15 months ago, # |
  Vote: I like it +8 Vote: I do not like it

Hope, this day, Max, will help everybody to reach their MAX rating)

wish u good luck and happy 30th birthday!!

»
15 months ago, # |
  Vote: I like it +13 Vote: I do not like it

Happy Birthday, Max c:

»
15 months ago, # |
  Vote: I like it +8 Vote: I do not like it

Happy Birthday Max:)

»
15 months ago, # |
  Vote: I like it +8 Vote: I do not like it

good luck & have fun

»
15 months ago, # |
  Vote: I like it +8 Vote: I do not like it

Happy Birthaday Max, Sending you best best best wishes

»
15 months ago, # |
  Vote: I like it +8 Vote: I do not like it

Looking forward for the contest desparately...

Also, Happy Birthday Max Tell him we sent virtual hugs :)

»
15 months ago, # |
  Vote: I like it +5 Vote: I do not like it

Happy birthday Max!

»
15 months ago, # |
  Vote: I like it +8 Vote: I do not like it

Lets Goo. My first coding contest ever. So anxious and excited at the same time

»
15 months ago, # |
  Vote: I like it +5 Vote: I do not like it

Dear Max, Warmest congratulations on your birthday! I hope this special day brings you immense joy, wonderful memories, and a year filled with success and happiness. Wishing you all the happiness your heart can hold. Warmest regards, Faizullakh, Dilettante_786

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

Who is Max?

»
15 months ago, # |
  Vote: I like it +8 Vote: I do not like it

As a participant I just hope to get rated and nothing else

Also Happy Birthday Max, sending you best wishes

»
15 months ago, # |
  Vote: I like it +3 Vote: I do not like it

can anyone tell me, if there is any correlation between the question's score and rating? A score of 1000 means, the question is around 1000 rating difficulty level?

  • »
    »
    15 months ago, # ^ |
      Vote: I like it -15 Vote: I do not like it

    Rating 1000 means that a person rated 1000 has a 50% chance of solving this problem DURING the contest

  • »
    »
    15 months ago, # ^ |
      Vote: I like it +24 Vote: I do not like it

    No, there is no exact correlation. Sometimes the scores might be close to the problem ratings, other times they might be very different. Scores try to reflect the difficulty of the problems (higher score — harder problem; much higher score — much harder problem) but it's often difficult to accurately determine the difficulty of the problems based on the opinion of only a handful of people (problemsetters and testers).

»
15 months ago, # |
  Vote: I like it +3 Vote: I do not like it

As a participant I hope to get 1600+ rating or even better,Become first time Expert.

»
15 months ago, # |
  Vote: I like it +1 Vote: I do not like it

As a participant I hope to get 1800+ rating or even better, Candidate Master

Also Happy Birthday Max, sending you the best wishes

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

    Candidate Master needs 1900 rating, not 1800.

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

      Yeah, he meant either 1800+ or, better than that, become a candidate master.

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

puranyaa

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

AGC Codeforces ?

»
15 months ago, # |
  Vote: I like it +10 Vote: I do not like it

It was a nice contest. Hoping to become Candidate Master in my next one. : )

»
15 months ago, # |
  Vote: I like it +4 Vote: I do not like it

Good visible tests! Really helpful. Hope pretests are good too.

»
15 months ago, # |
  Vote: I like it +6 Vote: I do not like it

-clear statement -nice problem that's a perfect contest , thanks to the organizers

»
15 months ago, # |
  Vote: I like it +27 Vote: I do not like it

How to solve C?

  • »
    »
    15 months ago, # ^ |
      Vote: I like it +24 Vote: I do not like it

    Believe in yourself

  • »
    »
    15 months ago, # ^ |
      Vote: I like it +44 Vote: I do not like it

    Write a brute force solution for small $$$n$$$ s and figure out that the optimal permutation is of form $$$1$$$ $$$2$$$ ... $$$x$$$ $$$n$$$ $$$n-1$$$ ... $$$x+1$$$.

    Stupid problem

    • »
      »
      »
      15 months ago, # ^ |
      Rev. 2   Vote: I like it +10 Vote: I do not like it

      Yes, I also got accepted this way but I don't know how to prove it.

      • »
        »
        »
        »
        15 months ago, # ^ |
          Vote: I like it +8 Vote: I do not like it

        I didn't make the observation. I solved it by iterating over the max product (n^2 iterations). Then go through all n-1 remaining indices from large to small and greedily take the biggest remaining value of the permutation, such that the product is at most the max element. Total runtime is (n^3*logn). Correctness is obvious, but needed small optimizations to squeeze in time limit (used that the maximum you can get for a fixed max product is (n-1)*max product).

»
15 months ago, # |
  Vote: I like it +8 Vote: I do not like it

Segment tree for E?

»
15 months ago, # |
  Vote: I like it +5 Vote: I do not like it

Speedforces

»
15 months ago, # |
  Vote: I like it +1 Vote: I do not like it

It was hard D for me,but easy for others :(

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

    Wouldn't say D was easy, it's expected complexity is around 1700.

»
15 months ago, # |
  Vote: I like it +23 Vote: I do not like it

New OEIS sequence when

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

Is it just me or was that round way harder than usual?

»
15 months ago, # |
  Vote: I like it +1 Vote: I do not like it

How to solve D?

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

    Hint: Ignore a and r.

    Hint2: Use merge segments.

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

      how do I find out which is the rightmost/best segment from which to start using binary search? i am using the same idea as merge segments (storing best answer for all segments) but I am unable to find out which segment I should be choosing.

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

        After combining the segments, x can only get into 1 segment (or not get into more than one). This is the segment you are looking for using binary search. In fact, the search can be reduced to upper_bound along the left border of the segments. After that, you take the previous one from what you found. The answer will be max(x,R) (R is the right boundary of the segment)

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

    combining segments plus binary search

»
15 months ago, # |
  Vote: I like it +1 Vote: I do not like it

Nice contest, hope to become expert this round!

»
15 months ago, # |
  Vote: I like it +1 Vote: I do not like it

Hi guys, I have a question that need your help.

Example with problem B, my idea: sort all arrays (A[n]), and the result is sum of second element each array (sum (A[i][1]), 1<=i<=n) (except the min — A[i][1] with 1<=i<=n), and the min value of all elements.

I tried to solve this problem with 3 — 4 wrong times answer. In each try, I realize something, and test the output with codeforces system, when wrong, I find some test cases, realize something (or not), and solve again. So, I cannot prove some problems I solved, like problem C. What happened with me! How can I improve my algorithm?

Also HappyBirthday Max.

»
15 months ago, # |
  Vote: I like it -7 Vote: I do not like it

how I solved C

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

Are there any hacks for problem F? I got Wrong Answer on Pretest 3.

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

    wrong answer 15954th numbers differ - expected: '58', found: '60'

    How could I debug my code with a hack I cannot see…

»
15 months ago, # |
Rev. 3   Vote: I like it -15 Vote: I do not like it

I have no idea how to solve A, but I know how to solve F:

First, let's notice that we will take courses at most $$$logmaxW$$$ times because after that time spent on traversing a road will be equal to $$$1$$$. Also, all courses will be taken in the first possible city/node (to minimize time spent on the rest of the travel). I have precomputed with binary lifting:

$$$up[i][j] -$$$ $$$2^j$$$-th ancestor of node $$$i$$$

$$$cnt[i][j] -$$$ the number of nodes $$$u$$$ on path from node $$$i$$$ to the $$$2^j$$$-th ancestor of $$$i$$$ such that $$$s[u]=$$$ '$$$1$$$'

$$$sum[i][j][k] -$$$ time spent on traveling from node $$$i$$$ to $$$2^j$$$-th ancestor of $$$i$$$ if the skill is equal to $$$c=2^k$$$ all the time (without including the time needed to take that $$$k$$$ courses).

Let's define $$$f(u,v,k) -$$$ time spent on traveling from node $$$u$$$ to node $$$v$$$ if the skill is equal to $$$c=2^k$$$. This can be calculated in $$$O(logn)$$$ using arrays $$$up[i][j]$$$ and $$$sum[i][j][k]$$$.

For answering the query ($$$a,b$$$), we will find the necessary time to travel from $$$a$$$ to $$$b$$$ for every $$$k$$$ from $$$0$$$ to $$$logmaxW$$$, where $$$k$$$ will be equal to the number of taken courses. For each of the results, we need to find the first node $$$u$$$ on the path from $$$a$$$ to $$$b$$$ such that $$$s[u] =$$$ '$$$1$$$' and the closest node $$$v$$$ to $$$a$$$, but not on the path from $$$a$$$ to $$$b$$$, such that $$$s[v] =$$$ '$$$1$$$ and the result will be equal to $$$min(k \cdot T + f(a,u,0)+f(u,b,k),k \cdot T + f(a,b,k))$$$ Final result will be the minimum of this results. Overall time and memory complexity are equal to $$$O(nlognlogmaxW)$$$.

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

    I coded it but it's WA

    we need to find the first node u on the path from a to b such that s[u]='1'

    I now think the bug is you need to also consider nodes not on path, like a detour off the path

    • »
      »
      »
      15 months ago, # ^ |
      Rev. 5   Vote: I like it -26 Vote: I do not like it

      Yes, I think you just need to find the closest on the path and not on the path $$$u$$$ with $s[u]$='1' for every node in tree, but this can be done by DFS or again by this LCA, the point is the same.

  • »
    »
    15 months ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    Wait, but what if there is no node $$$u$$$ such that $$$s[u]$$$='1' on path from $$$a$$$ to $$$b$$$. Don't we need to go somewhere off path to take courses and then return?

  • »
    »
    15 months ago, # ^ |
    Rev. 4   Vote: I like it +26 Vote: I do not like it

    This doesn't work. Consider a simple test case:

    1
    3 1
    1 2 1
    2 3 100
    101
    1
    2 3
    

    Your solution will go directly from $$$2 \rightarrow 3$$$ incurring a cost of $$$100$$$, when the optimal solution should actually be to go to $$$1$$$ first, complete courses, and then go $$$1 \rightarrow 2 \rightarrow 3$$$ with a total cost of $$$10$$$. Finding the closest course to $$$a$$$ and using it as a checkpoint is also not fully correct:

    1
    7 1
    1 2 1
    2 3 1
    3 4 100
    3 5 1
    1 6 1
    6 7 1
    0000101
    1
    1 4
    

    In this case, it is better to take the courses at $$$5$$$ rather than $$$7$$$, even though it is further. A full solution must take the closest detours to every vertex on the path from $$$a \rightarrow b$$$ into account, which is what gives the problem its difficulty.

    • »
      »
      »
      15 months ago, # ^ |
        Vote: I like it -39 Vote: I do not like it

      I have edited my solution, so it covers that case now. It would be nice if you could read the post before replying.

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

        The second counterexample proves that your edit is also incorrect. It would be nice if you could read the comment before replying.

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

          Oh my bad. In that case, we can for every node remember the closest nodeand than for the path in $$$logn$$$ find optimal one or?

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

            Yes, the key is to isolate the terms that depend on where the detour off the shortest path starts, and then find the minimum of these terms using binary lifting. Of course, there are many more details to what I've just described, but I will leave that for you to figure out.

»
15 months ago, # |
Rev. 2   Vote: I like it +13 Vote: I do not like it

I solved C by pre-computing and saving the answers :)

Edit: I also forgot to congratulate Max, HBD Max :D

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

    how did you precompute values ?

    • »
      »
      »
      15 months ago, # ^ |
        Vote: I like it +4 Vote: I do not like it

      By pre-precomputing them.

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

        how did he pre-pre-precomputing them?

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

          My question here is if he has a function that precomputes less than n^4 so he has a solution then why precomputing? :"D

          you can't precompute be generating all permutations so I think he had a n^4 solution :

»
15 months ago, # |
  Vote: I like it -6 Vote: I do not like it

so disappointing when u are rank 2 15 min in the contest and now ur rank 500 at the end cuz some stupid mistakes... got a little positive delta though, nice little birthday present:P

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

I mistakenly read the meaning of problem B and got stuck for a long time.

Anyway, thank you for holding this high-quality round!

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

    You thought that you can move an element only once right?

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

218576719 For A problem , can someone please tell me why am I getting runtime error(at pretest 1), even when this code runs fine in my sublime text.

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

Can anyone help me with what's wrong with this code for problem D? My basic idea was to sort the segments and stitch them together and finally apply a binary search for each xi to see in which stitched segment it lies.

Spoiler
»
15 months ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

Problem A: You can just sort the array. Find the subarray starting from the first element, ensure that all elements of the subarray are equal, and just print the subarray. The next part will be for array C.

Problem B: Just store the first and second minimums from all arrays. Then sort the stored values. The ans will be first [0] + second [1] + second [2]...+second [n-1]

Problem C: Create a permutation of size n. Then use a for loop. Reverse the given sorted permutation for j = i to n. Calculate and store the maximum of all n possible answers.

I hope it is helpful.

»
15 months ago, # |
Rev. 3   Vote: I like it -12 Vote: I do not like it

Hello, I would like to report an issue on question 4. Basically, I ran the code on two different online C++ compilers. For the first test case, I got the correct results on those sites. However, when I run the same exact code using CodeForces, these are the results it is giving.

14 14 23 15 28 22 
14 14 14 14 22 1967396643 14 14 15 
7 8 7 
15 14 14 30 24 17 31 4 8 
32 32 32 5 8 1967396643 4 32 

I am losing my mind because I have no clue where this random large numbers are coming from in 2nd and 5th lines. Can someone either explain or if CodeForces admin thinks this is a mistake on their side, can I get the credit for the problem?

Here's my code:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
using namespace std;


int main()
{
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        pii arr[n];
        for (int i = 0; i < n; i++) {
            int l,r,a,b;
            cin >> l >> r >> a >> b;
            arr[i] = make_pair(b,l);
        }
        int q;
        vector<int> original;
        vector<pii> queries;
        queries.clear();
        cin >> q;
        for (int i = 0; i < q; i++) {
            int x;
            cin >> x;
            queries.push_back(make_pair(x, i));
            original.push_back(x);
        }
        sort(queries.begin(), queries.end());

        sort(arr, arr+n);
        vector<pii> brackets;
        pii currbracket = make_pair(-1,-1);
        for (int i = 0; i < n; i++) {
            if (currbracket.first == -1) {
                currbracket = arr[i];
                continue;
            }
            pii currele = arr[i];
            if (currele.second <= currbracket.first) {
                currbracket = make_pair(max(currbracket.first, currele.first), min(currele.second,currbracket.second));
                if (i==n-1) {
                    brackets.push_back(currbracket);
                }
            } else {
                brackets.push_back(currbracket);
                currbracket = make_pair(-1,-1);
                if (i==n-1) {
                    brackets.push_back(arr[i]);
                    break;
                }
                i--;
            }
        }
        int ans[q];
        int index = 0;
        for (int i = 0; i < q; i++) {
            int currquery = queries[i].first;
            while(index < n && currquery > brackets[index].first) {
                index++;
                continue;
            }
            if (index >= n) {
                ans[queries[i].second] = original[queries[i].second];
            } else {
                if (currquery < brackets[index].second) {
                    ans[queries[i].second] = queries[i].first;
                } else {
                    ans[queries[i].second] = brackets[index].first;
                }
            }
        }
    
        for (int i = 0; i < q; i++) {
            cout << ans[i] << " ";
        }
        cout << "\n";
        
    }
    return 0;
}
  • »
    »
    15 months ago, # ^ |
      Vote: I like it +2 Vote: I do not like it
    int n;
    cin >> n;
    pii arr[n];
    

    This is a prime example of a VLA, which is known to be unreliable (and isn't even provided by standards), so it's a likely source of problems. Use std::vector or a large global array instead.

    • »
      »
      »
      15 months ago, # ^ |
        Vote: I like it +5 Vote: I do not like it

      The failure had nothing to do with VLA's though (see my reply to the parent comment for details).

      Also, I wouldn't say that VLA's are “unreliable”. It is true that they are not part of the C++ standard, but they are supported by most compilers, including GCC which is used by CodeForces. Compilers that don't support them will give a clear compiler error instead of doing something unpredictable.

      The main risk to be aware of is that VLA's are allocated on the stack instead of the heap. That's both their advantage and disadvantage. The advantage is that allocation is cheap compared to heap allocation with std::vector<>, especially for small vectors. The disadvantage is that you can overflow the stack when the array is bigger than remaining stack space. Fortunately, CodeForces uses a 256 MB stack size, so you can put a lot of data on the stack before this becomes a problem. For example, the arr array in this problem takes less than 2 megabytes.

      I would agree that in most cases using a std::vector<> is better, especially when the size of the array is likely to be large. In that case, the overhead of heap allocation is negligible.

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

        Fair, I've just had several occasions where VLAs did seem to turn out to be the issue (well, at least replacing them would seemingly fix the problem), so I often can't help but point it out whenever I see people using them. In addition, the underlying stack manipulation (especially when used inside a loop and with several VLAs in the same frame) still seems hacky to me. However, I've also avoided e.g. std::array for a while because of a few problems some time ago, so I'm probably not the most up-to-date on what's currently broken and what is not.

  • »
    »
    15 months ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    The problem is that brackets.size() can be less than n, so in the bottom part of your solution you should replace n with brackets.size(), or you will access the brackets vector out of bounds, which gives unpredictable results.

»
15 months ago, # |
  Vote: I like it +5 Vote: I do not like it

Thanks for this great round, Also Happy Birthday Max

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

how to solve E?

»
15 months ago, # |
  Vote: I like it +24 Vote: I do not like it

is there a way to prove and solve C without resorting to brute force with next_permutation and print? What happen if a certain language doesn't have next_permutation like C++?

If it's not easy to prove and much easier to observe by brute force then it's total BS

  • »
    »
    15 months ago, # ^ |
    Rev. 2   Vote: I like it +11 Vote: I do not like it

    I took a O(n^3log(n)) approach which passed pretests in 2745ms. Out of fear of FST I then tried optimizing it without any success before deciding, "What the hell, let's just precompute all the answers".

    The approach I used was to fix i and j such that p_i=j and i*j would be the maximum value of p_i * i. Then try to place the values in descending order.

    Edit: it turns out my approach was actually the intended one (although I didn't manage to optimize the log factor. Maybe I was just paranoid). I suppose this shows how most people would go for a proof by AC instead of taking an approach that is much easier to verify but slower.

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

    I'm also not a fan of problems that are of the form “brute-force some cases, spot the pattern, guess that it generalizes, and then code up the pattern”. I actually solved problem D before C because of that reason: at least problem C you could reason about.

    But I don't think brute forcing permutations requires C++. Even in Python you can do it easily:

    from itertools import permutations
    
    def Evaluate(perm):
      terms = [i*v for i,v in enumerate(perm, 1)]
      return sum(terms) - max(terms)
    
    for n in range(2, 10):
      print(*max(permutations(range(1, n+1)), key=Evaluate))
    

    That's simple enough, and every self-respecting programmer should have Python installed.

»
15 months ago, # |
  Vote: I like it +1 Vote: I do not like it

Yay! Hello expert for the third time. Why is my performance so inconsistent? :(

»
15 months ago, # |
  Vote: I like it +1 Vote: I do not like it

Thanks for this great round that is full of ideas .

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

Auto comment: topic has been updated by i_love_penguins (previous revision, new revision, compare).

»
15 months ago, # |
  Vote: I like it -8 Vote: I do not like it

I'm new to the platform, don't know how it works completely but solution like this should be illegal right? 218544590

»
15 months ago, # |
  Vote: I like it +16 Vote: I do not like it

might be one of the most trash solutions of A, but i solved it using scc (strong connectivity components). I built a graph where edge uv meant v % u = 0 and get all scc using Kosaraju algorithm. Then, if there is just one component, there's no solution; otherwise we can put the last component (in topological sort of condenced graph) into c-array and other components into b-array.

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

I thought those with rating above 2000 don't read whole problem and just go through the code just by reading Input/Output section. And that mistake costed me time and patience -_-

In first problem I submitted without knowing that I was supposed to print the size of array B & C (How dumb can I Be :( .. ) Still hope to get +ve delta

And can someone explain how to apply BS in D? I tried but it was too new way to implement that I failed. Please explain :)

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

    You don't get penalty for failing example test

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

      But late submissions gets lesser points ^_o

      ( That calculator looks dope. )

»
15 months ago, # |
  Vote: I like it +1 Vote: I do not like it

Thank you for this contest!

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

Can anyone provide their lazy segtree implementation to D?

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

    Here

    Idk what happened but it was showing failed on system test but now it's accepted. Were the solutions rejudged or something?

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

    How did you use a lazy segtree ? What I did was processing the ranges by decreasing end and maintaining a dp which can be calculated with only a max segtree

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

      After figuring out the answer for a portal, update it's entire range [l, r] with that.

      Is there a way to solve it without lazy segtree? (not the set one though)

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

        I solved it with "only" a max segtree.

        Basically, each portal will be considered as [l, b] (because we can show it is optimal to jump on b, indeed, assume we don't, then any portal we will use to jump further than b could be used starting from b).

        Consider portals by decreasing end (and also consider queries at the same time, they are just special portals [v, v], also it's important to consider portals before queries in case of equality).

        Assume we know the answer for all the portals with a greater end than the current portal. Say the current portal is [l, b]. To improve our answer, we can jump on any portal [i, j] such that j > b and i <= b. The answer starting at the given portal is just the maximum of the answer of all such portals.

        We can maintain it with a max segment tree. When we just computed the answer for a portal [l, b], we chmax the position l with the value b.

        Now, to get the answer, we just need to query the maximum on the range [0, b].

        Here is my implem: 218572801

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

        You can solve it using dp and compressing in O((n+q) log n).

        I'm honestly surprised by the amount of people who used segtree.

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

The constraints for problem C were too lenient. it is not difficult to find an n^2 solution

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

Is problem C pure calculations or just intuition?

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

I don't know how my solution passed for C and D.

»
15 months ago, # |
  Vote: I like it +37 Vote: I do not like it

The solution to problem C, O(1) cpp void solve() { int n; cin >> n; vector<int> a={0,2,7,17,35,62,100,152,219,303,406,530,678,851,1051,1280,1540,1834, 2163,2529,2934,3380,3869,4403,4985,5616,6298,7033,7823,8670,9576,10544,11575, 12671,13834,15066,16369,17745,19196,20724,22332,24021,25793,27650,29594,31627, 33751,35968,38280,40690,43199,45809,48522,51340,54265,57299,60444,63702,67075, 70565,74175,77906,81760,85739,89845,94080,98446,102945,107579,112350,117260, 122312,127507,132847,138334,143970,149757,155697,161792,168044,174455,181027, 187762,194662,201730,208967,216375,223956,231712,239645,247757,256050,264526, 273187,282035,291072,300300,309722,319339,329153,339166,349380,359797,370419, 381248,392286,403535,414997,426674,438568,450681,463015,475573,488356,501366, 514605,528075,541778,555716,569891,584305,598960,613858,629001,644391,660030, 675920,692064,708463,725119,742034,759210,776649,794353,812324,830564,849075, 867859,886918,906254,925869,945765,965944,986408,1007160,1028201,1049533,1071158, 1093078,1115295,1137811,1160628,1183748,1207173,1230905,1254946,1279298,1303963, 1328943,1354240,1379856,1405794,1432055,1458641,1485554,1512796,1540369,1568275, 1596516,1625094,1654011,1683269,1712870,1742816,1773109,1803751,1834744,1866090, 1897791,1929849,1962267,1995046,2028188,2061695,2095569,2129812,2164426,2199413, 2234775,2270514,2306632,2343131,2380013,2417280,2454934,2492977,2531411,2570238, 2609460,2649080,2689099,2729519,2770342,2811570,2853205,2895249,2937704,2980572, 3023855,3067555,3111674,3156214,3201177,3246565,3292380,3338624,3385299,3432407, 3479950,3527930,3576350,3625211,3674515,3724264,3774460,3825105,3876201,3927750, 3979754,4032215,4085135,4138516,4192360,4246669,4301445,4356690,4412406,4468595, 4525259,4582400,4640020,4698122,4756707,4815777,4875334,4935380,4995917,5056947, 5118472,5180494}; cout << a[n-1] << endl; }

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

    wtf orz you have 1000iq, I spent inf time optimising to N^3 while I could just have done this

    • »
      »
      »
      15 months ago, # ^ |
        Vote: I like it +4 Vote: I do not like it

      hh, I only have O(N^3logN) solution , I don't want to find other algo ,so I try to make the tables which cost my 30 minites

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

    This is actually quite nice. But how weird is the fact that you need to already have an O(N^3logN) solution to do this kind of stuff....

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

      Yes, I only have O(N^3logN) solution , I don't want to find other algo ,so I try to make the tables which cost my 30 minites

»
15 months ago, # |
  Vote: I like it +6 Vote: I do not like it

Amazing contest! Problems were high-quality and fun to solve. Thanks to kristevalex, i_love_penguins, efimovpaul, induk_v_tsiane and all the other testers!

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

Auto comment: topic has been updated by i_love_penguins (previous revision, new revision, compare).

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

Nice Contest!

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

»
15 months ago, # |
  Vote: I like it +1 Vote: I do not like it

Happy Birthday to MAX.

Video Editorial For Problem A,B, D and C.

https://youtu.be/wxtpQIPOHgE

Also I shared how I approached C during contest and was able to pass it but was not able to prove it.

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

Hi. First of all I'd like to thanks the authors for this great round !

I got TLE on problem C (I had a badly written $$$O(N^3 log n)$$$ solution). At that time, problem C had < 500 AC.

I spent 30 minutes to optimise my solution and at that time the problem already had almost four thousand AC.

I think that it is most likely because people wrote a bruteforce and guessed the pattern from it.

I have nothing against this (because I could have done it too, guessing is a tool that anyone can use in contests).

However, I just wanted to know what people think about such problems where writing a bruteforce and guessing a pattern makes it extremely obvious. Is it okay to have such problems in rounds on a regular basis ?

I'm not even sure of my own opinion but the thing is that I feel like the proof of such a pattern is way above the scope of div2 C while guessing it is way easier. idk

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

When I know the F was changed,I hadn't enough time to solve it.

So can this be unrated for me?

I have solved E&F after the contest.

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

Thanks for the nice contest ! And especially for problem D :)

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

I gave my first contest today, round 892 div 2 but my rating did not increase. I am able to see round 892 in unrated contest section in my profile. I was only able to solve one problem. can someone tell me why rating did not increase

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

    Don't worry bro. It won't publish immediately after contest ends. Within one day, it gets reflected for all the participants. Welcome to the platform & All the best for upcoming journey.

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

      oh, okay.. thanks for the best wishes.

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

        It released just now. Congrats on your first increase.

»
15 months ago, # |
  Vote: I like it +9 Vote: I do not like it

Thanks for great round!

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

constructive forces

but the problems are good.

»
15 months ago, # |
Rev. 3   Vote: I like it -8 Vote: I do not like it

Fancy round! Though div2C could be easily solved in about $$$O(n^2)$$$ time by iterating over every mirroring of suffix and prefix (firstly, try mirroring every suffix, then try mirroring every prefix). Indeed, such solution gets AC: 218645309.

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

I wanted to ask why can we sort the array in question 2 without exceeding the time limit? Wont the time complexity exceed: let sum of mi=m O(t*(mlogm))=(2.5*10^4*(5*10^4*15)) =18.75*10^9, which is a lot more than allowed time?

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

I don't think C is a good problem.Because if the intended solution in the editorial is the only solution then it's a very good prblm and a deserving way to get AC in this prblm is to go through that approach . However , if you brute force in small constraints then you find a very obvious pattern and that ruins the prblm , that is why C has got these many ACs

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

    Hi!

    We're sorry that this happened, the task was cool with the intended solution, and we felt like not a lit of people would look for the pattern, so we decided to keep it as it was.

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

      it's ok , no need to be sorry , I know that problem-setting is a hard Job , good job on authoring the contest

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

Happy Birthday Max, sending you best wishes