awoo's blog

By awoo, history, 13 months ago, translation, In English

1902A - Binary Imbalance

Idea: BledDest

Tutorial
Solution (awoo)

1902B - Getting Points

Idea: adedalic

Tutorial
Solution (adedalic)

1902C - Insert and Equalize

Idea: Roms и BledDest

Tutorial
Solution (awoo)

1902D - Robot Queries

Idea: BledDest

Tutorial
Solution (Neon)

1902E - Collapsing Strings

Idea: Roms

Tutorial
Solution (Roms)

1902F - Trees and XOR Queries Again

Idea: BledDest

Tutorial
Solution (BledDest)
  • Vote: I like it
  • +43
  • Vote: I do not like it

| Write comment?
»
13 months ago, # |
  Vote: I like it -21 Vote: I do not like it

E was awesome. Thanks for great problems

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

When will you update the rating change for this round?

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

    It has been unrated I guess

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

      How could that be!? Contest title clearly says it's Rated for Div2

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

        Idk but when I filtered my contests to only unrated.I found it there so I thought maybe it was made unrated.

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

          All contests are shown under 'unrated' before ratings are updated. You can't make any assumtions based on that. If a contest is made unrated, it will be announced on the original contest announcement.

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

    I've noticed that my position on the leaderboard has increased after the competition fully finished. Maybe they are trying to prune out cheaters?

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

C was the coolest

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

Thank for contest! But where is rating?

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

It's amazing to see how much implementation matters in Question D — the solution by Neon is so concise and pretty.

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

awoo, I think there is a typo in the editorial for Problem 1902E - Collapsing Strings. It should be $$$|C(a,b)|=|a|+|b|− \textbf{2} \times |LCP(a′,b)|$$$.

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

    Thank you, will be fixed in a couple of minutes

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

F was cute :)

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

For Problem D

How Δi,j is found over there in editorial? Is there a simpler way?

I did this in the below given way

Found the pattern of how reversing changes the path(about what lines the pattern is reflected) and accordingly what distance each point is moving with respect to reflections, there by finding the Δi,j.

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

    If you reach point p=path[l]+d then when commands are reversed you'll have to walk d to reach the end: rp+d=path[r]

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

    You can also see that the path with reversed actions is obtained through a 180-degree CCW rotation and a shift.

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

I feel like tests for F are not really strong or otherwise, I am not sure why my $$$O(n \log n B^2 + q B^2)$$$ solution 235594622 is so fast. I didn't try to optimize anything.

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

LOL, I feel so stupid after looking at the editorial for B. but I am happy to have learnt these "new"(for me) techniques (especially, generating files to find failing testcases, use of ceil() function, proving a greedy approach) and I believe that is one of the main objective of the EDU rounds! I tried to apply greedy approach, was not able to figure out on which cases the code was failing, after like 5 submissions I realized that first ,I should find those days where 2 tasks can be completed like on day 8, 22, 36 etc and add (l+2*t) to points. Then if still points are not enough, add (l+t) to answer if left with any task, and then finally add any remaining points in the form of l. this is my messy solution 235754545. looking forward to better performances in the future.

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

The Trie answer for E is accepted by PyPy3 but not PyPy3-64. :(

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

    Yeah had the same issue, from what i saw you can use lists instead of dicts to pass it, and since there are only 26 letters at max you can check in O(1) time if the element exists.

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

    Generally i feel like Div 2 E is as far as you can get with python, which is why i am trying to transfer to C++. I have had it happen so many times, that i couldn't pass E, but after translating my code to C++ it passed.

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

What is the difference between https://codeforces.net/contest/1902/submission/235770255 and https://codeforces.net/contest/1902/submission/235600034 ? Why does it work when I change beginning to 2n*sum(1->n) then subtract and not when i continuously add to a starting val of 0 length*n+sum-subtracted value . of lengths? When I use summation rules the outcome is the same.

(totallength+(sum of all individual length(which is total length)))*n = 2n sum of all length, then I did not change the way I calculated what I need to subtract subtract.

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

    The second code doesn't work since s.length()*n can overflow.

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

My first time solving every problem before editorial))))

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

So, it means that the points that the robot visits can be represented as follows: for an integer k such that l≤k≤r, perform all commands from 1 to r, except for the commands from l to k

Could someone explain this part of the tutorial for D please?

For example if a take k = l, the this means that I'll make all the commands from 1 to l-1 and then from l+1 to r? I don´t get it :'(

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

    It means you can check the path for the commands from 1 to l-1 and then from r to the end.

    Notice that when you flip the instructions from l to r, the path from 1 to l-1 is unaffected (because nothing has changed for those parts).

    Now notice that when you flip the instructions, you are just changing the order of instructions, the instructions that are carried out are still the same (in other words, if there are 5U and 5L before flipping, there will still be 5U and 5L after flipping, the order is just different).

    Let us take the change in coordinates caused by flipped instructions as {dx, dy}.

    Notice that dx = number of r — number of l, and dy = number of u — number of d. Since the number of instructions for each direction remains unchanged, we can conclude that dx and dy remains the same.

    All this means is that before flipping, we start at the same place, and after flipping, we end at the same place as compared to our original path. Since there are no changes to the instructions after flipping, we can also conclude that the path before and after flipping is the same.

    Hence, we can check the original path for 1 to l-1 and r to the end, then check the reversed path (with some simple math) from l to r.

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

      Thank you ArtemiszenN!! Actually it was not the answer I was lookinfor but you made me notice something important to understand what I was asking and that is the instructions remain the same just in other order.

      Literally I couldn't notice that when taking k and process instructions from 1 to l-1 and then from k+1 to r leads to the same coordinate when processing instructions from 1 to l-1 and then the first k instructions in the flipped string.

      Thank you ^-^

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

The solution of problem F in $$$O(n\log^2 V)$$$ is awesome! I just came up with a simple $$$O(n\log^3 V)$$$ solution:

Through the definition of XOR base (mentioned in the official tutorial) we can conclude that for two integer set $$$A$$$ and $$$B$$$, $$$X(A\cup B) = X(X(A)\cup X(B))$$$, where $$$X(S)$$$ means the XOR base of an integer set $$$S$$$. Through, we can merge two XOR base in $$$O(\log^2 V)$$$ time: Simply insert all element of $$$X(A)$$$ and $$$X(B)$$$ into the resulting XOR base.

Therefore, using binary lifting algorithm on tree just like solving LCA, we get an $$$O[(n + q)\log^3 V]$$$ solution.

Usually the $$$O[(n + q)\log^3 V]$$$ complexity with no optimization can't pass all tests (TLE on test [70, 93]). So here's a trick to improve your constant factor: When adding integers into a XOR base $$$B$$$, if $$$B$$$ has exactly $$$20$$$ element, then do noting, because it will not change any element of $$$B$$$. Hope this will help you.

Here is an example: (C++)

XOR Base Example
»
13 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone please explain how do we arrive at $$$2*n \sum_{i=1}^{n} Si - 2* \sum_{i=1}^{n} \sum_{i=1}^{n} LCP(Si', Sj)$$$.

I wanna know specifically how do we get $$$2*n \sum_{i=1}^{n} si$$$. Thankyou!

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

    Oh I get it each string occurs $$$2*n$$$ times, once on it's own pairs, and once paired with others.

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

Problem C: Can someone please help me out to understand the limitation of using int[] compared to long long[] for storing all the values in an array.

using long long: https://codeforces.net/contest/1902/submission/235786184

using int: https://codeforces.net/contest/1902/submission/235786137

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

why does an $$$O(n \ log \ n)$$$ hash based solution for E TLE :/ slow modulo?

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

I have problem that a lgm can't answer,and if someone is able to, everyone will admire him and he will be legend

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

For D, i suppose offline queries ( sorted by r) method would be more easier. Then no need of binary search also. submission

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

Can anyone please help me in identifying the mistake in the code? My logic is correct but I am not able to identify a case where it is giving a zero answer.

Submission

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

My code for problem D is giving tle at test 41. Here is the code https://codeforces.net/contest/1902/submission/241087945 Can anyone suggest any optimization that can be done here. Thanks

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

I tried to solve problem E using Trie, but it repeatedly gives Memory Limit Exceeded on test case 16. I don't see any mistake in the construction of the Trie and looks like it used O(S*26) memory. Any sort of discussion will help a lot. This is the submission link : https://codeforces.net/contest/1902/submission/244942580

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

Reverse the operation sequence, and the new path is equivalent to the original path being symmetrical about the midpoint of the starting and ending line.

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

nice

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

could anyone tell me why i am getting tle on test case 41? my solution is of o(nlogn) {if i am not wrong} . and by seeing constraints it should pass the testcases?. anyone?

sumbission link :- https://codeforces.net/contest/1902/submission/256209886

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

Plz help with this submission for problem E, couldn't find any reason for a runtime error. It passes all small test cases. Integer overflow is taken care of.

https://codeforces.net/contest/1902/submission/287423396