awoo's blog

By awoo, history, 3 years ago, translation, In English

1620A - Equal or Not Equal

Idea: BledDest

Tutorial
Solution (Neon)

1620B - Triangles on a Rectangle

Idea: BledDest

Tutorial
Solution (awoo)

1620C - BA-String

Idea: BledDest

Tutorial
Solution (awoo)

1620D - Exact Change

Idea: adedalic

Tutorial
Solution (adedalic)

1620E - Replace the Numbers

Idea: Neon

Tutorial
Solution 1 (Neon)
Solution 2 (Neon)

1620F - Bipartite Array

Idea: BledDest and Neon

Tutorial
Solution 1 (Neon)
Solution 2 (Neon)

1620G - Subsequences Galore

Idea: BledDest

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

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

In my opinion, I think that the positions of E and D should have been swapped.

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

In the problem E-Replace the Number, alternate solution mentions the small to large method. Can anyone explain how it has complexity of O(n log n)? Any resource added would also be helpful.

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

    With small to large method you want to take the smaller set and add it the larger one. When you do this if you had an element in the smaller set, now it is, for sure, in a set with size at least twice the one beforehand. So you can move each element at most log(n) times since the set can't become more than the number of elements.

    Here in the task you can keep them in vectors and if needed just swap the vectors after adding the smaller one to the larger.

    Hope that explains it.

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

    When you merge a smaller set into a larger set, the size of the generated set is at least twice of the smaller one. So the set-size will exceed N in no more than log(N) merges.

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

Mike, please please remove cheaters, I am at 1899

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

    your performance graph is pretty good, You will obviously make it to Red soon even if there are cheaters.

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

      Thanks for saying I might be red one day, I don't really care much about cheaters. I am just hoping I get +1 rating point to get CM for the first time and that can happen only when someone above me is removed.

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

I upsolved E using map of list as merging list is O(1) operation.

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

Can someone please explain why this DSU based solution for E is failing TC 4?
I am using a hashmap and a pointer array to map the representatives to the values and vice-versa; and everything seems to be working fine.
My Submission.

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

In case you are interested in video solutions, Here they are(for A-E)

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

In C , are there any constraints on the total number of strings possible ? Will it be always in the INT range ?

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

Getting TLE in Problem E, with this solution. Can somebody tells why because it seems more efficient than one in the solution 2 of tutorials.

https://codeforces.me/contest/1620/submission/139879128

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

    TLE because of how you are processing your 2nd type of querry.

    consider 10^5 querries of 2nd type like

    2 1 2

    2 2 3

    2 3 4

    ....

    that is in the end converting all 1 to some large number

    if the vector containing index of 1 has 10^5 elements

    Do you see where you are going wrong?

    10^5 x 10^5 operations there is your TLE

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

https://codeforces.me/contest/1620/submission/139877833 Can someone explain why this submission gives TL on E? It should be O(n) since double-linked list concatenation is O(1) operation... Thanks.

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

In problem E why my solution is wrong this one.any suggestion or testcase

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

    I think you should handle the case when 2 x y and x = y

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

      I am not able to understand why this case when 2 x y and x = y has to be specially handled?

      what is wrong with updating x with parent[x]?

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

        it depends on your solution, in my case, it was because :

        colorInd[oldColor] = -1; 
        

        so I'm deleting the old color although I should keep it. you can check my solutions and compare.

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

Can someone tell me some similiar problem as E, or some algorithm tag?

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

In the editorial of D,

no need to take more than $$$3$$$ coins $$$1$$$ and more than $$$3$$$ coins $$$2$$$

I think you meant,

no need to take more than $$$2$$$ coins $$$1$$$ and more than $$$2$$$ coins $$$2$$$

Because, in the given solution code, you are iterating from $$$i = 0$$$ to $$$i \lt 3$$$. And, I have also done the same :)

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

C problem is really amazing. And the solution is lot more amazing.

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

I have a different solution to F

following the editorial, there can't exist $$$i<j<k$$$ such that $$$a_{i} > a_{j} > a_{k}$$$. if an array satisfies this condition then the array can be decomposed entirely into two or less increasing subsequences.

Proof: consider doing a pass through the array and greedily picking out an increasing subsequence. Do two such greedy passes through the array let $$$S$$$ be the sequence chosen by the first pass and $$$T$$$ the sequence chosen by second pass. Assume there exist an index $$$k$$$ that isn't chosen by either sequences pick such smallest $$$k$$$, indexes $$$1$$$ to $$$k-1$$$ can't be all in $$$S$$$ otherwise $$$k$$$ would be in $$$T$$$, this implies there exist an index $$$i$$$ with $$$i+1$$$ < $$$k$$$ such that $$$i$$$ is in $$$S$$$ and $$$i+1$$$ is in $$$T$$$. Pick $$$j$$$ such that all indexes from $$$i$$$ to $$$j$$$ are in $$$T$$$ but $$$j+1$$$ is not. then $$$a_{i} > a_{j}$$$ otherwise some index between $$$i+1$$$ and $$$j$$$ would had been chosen by $$$S$$$ and $$$a_{k} > a_{j}$$$ otherwise $$$k$$$ would have been chosen by $$$T$$$ so we get $$$a_{i} > a_{j} > a_{k}$$$ which is impossible. For the other direction if there exist a length 3 decreasing subsequence then all three must be in different increasing subsequences.

Great!now we can construct a dp that tries to builds two or less increasing subsequences. Let $$$dp_{0 / 1,i}$$$ be the minimum possible value of the end of the increasing subsequence that $$$i$$$ is not part of(consider the end of the subsequence to be $$$-\infty$$$ if its empty) , $$$0/1$$$ denotes whether we choose to flip the sign of $$$p_{i}$$$, the transitions are deciding whether or not to stick $$$p_{i}$$$ into the same subsequence as $$$p_{i-1}$$$ ,the answer is yes if either $$$dp_{0,n}$$$ or $$$dp_{1,n}$$$ $$$\neq\infty$$$

my submission :140109080 (in hindsight the dp I described should be equivalent to the editorial dp, but I think this interpretation is cleaner and easier to understand)

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

please can someone tell me why is this code failing for C ?? https://codeforces.me/contest/1620/submission/140169385 I have lost my mind at debugging this for 3 hours at this point,also is there a way to see the full testcase in this website ?

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

Nice problems

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

In problem C, for this test case

TC:
                1
                8 3 18
                a***a*

The output of the editorial code is abbabbb i.e; (2+1) * (3+1) => 12th lexicographically smaller but I asked for 18th right. How is this correct?

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

    Your test has n=8 and the string is length 6 — something is wrong.

    However, that's not how you obtain the number from its digits. Consider base 10. If you have a number, consisting of digits 1, 2 and 3, then this number is 1 * 10 * 10 + 2 * 10 + 3. Same here. You have a number, consisting of digits 2 and 3 (the lengths of b segments in the answer). Thus, the number is 2 * (3 + 1) + 3 = 11. So this is the 12th string but if n was equal to 6 in your test.

    If the string instead was *a***a* and the answer was babbabbb, then the number would be retrieved as 1 * (3 + 3 + 3 + 1) * (3 + 1) + 2 * (3 + 1) + 3. So you have to multiply each digit by the bases of lower digits and add up the results.

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

I really dont understand the problem D. Why there is no need to take more than 3 coins 1 and more than 3 coins 2? In my opinion, there is no need to take more than one coin 1 (i.e. one coin 1 at most) because if any ai required two coins 1, two coin 1 could be replaced by one coin 2; and ,similarly, there is no need to take more than two coins 2. This really confuses me. Could anyone explain it? Thanks in advance!

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

I solved E using Linked list in O(n) https://codeforces.me/contest/1620/submission/141979731

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

Does anyone know why this solution to E is getting an MLE on testcase 4? 143353188

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

Edit: I see why because of this link: https://codeforces.me/blog/entry/64625 check it. Problem G: Some contestant solved this problem using inclusion-exclusion, let cnt be the number of strings that are subsequence of the strings given by the mask, they do +cnt when the amount of bits is odd and -cnt when is even. Then, they do dp[mask] = cnt and apply SOS DP at the end. SOS Dp is clear, but what is the argument of that inclusion-exclusion when adding and decreasing depending on the bits?

Sorry for my English, thanks in advance.