Блог пользователя awoo

Автор awoo, история, 3 года назад, По-русски

1620A - Равно или не равно

Идея: BledDest

Разбор
Решение (Neon)

1620B - Треугольники на прямоугольнике

Идея: BledDest

Разбор
Решение (awoo)

1620C - BA-строка

Идея: BledDest

Разбор
Решение (awoo)

1620D - Без сдачи

Идея: adedalic

Разбор
Решение (adedalic)

1620E - Замена чисел

Идея: Neon

Разбор
Решение 1 (Neon)
Решение 2 (Neon)

1620F - Двудольный массив

Идея: BledDest и Neon

Разбор
Решение 1 (Neon)
Решение 2 (Neon)

1620G - Подпоследовательности повсюду

Идея: BledDest

Разбор
Решение (BledDest)
  • Проголосовать: нравится
  • +66
  • Проголосовать: не нравится

»
3 года назад, # |
  Проголосовать: нравится +31 Проголосовать: не нравится

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

»
3 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

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 года назад, # ^ |
      Проголосовать: нравится +25 Проголосовать: не нравится

    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 года назад, # ^ |
      Проголосовать: нравится +2 Проголосовать: не нравится

    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 года назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится
»
3 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

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

»
3 года назад, # |
  Проголосовать: нравится +60 Проголосовать: не нравится

Mike, please please remove cheaters, I am at 1899

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +18 Проголосовать: не нравится

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

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится +34 Проголосовать: не нравится

      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 года назад, # |
  Проголосовать: нравится +16 Проголосовать: не нравится

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

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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.net/contest/1620/submission/139879128

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    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 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

https://codeforces.net/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 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

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

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      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 года назад, # ^ |
        Rev. 3   Проголосовать: нравится +3 Проголосовать: не нравится

        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 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

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

»
3 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

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 года назад, # |
  Проголосовать: нравится +12 Проголосовать: не нравится

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

»
3 года назад, # |
Rev. 3   Проголосовать: нравится +8 Проголосовать: не нравится

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 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

please can someone tell me why is this code failing for C ?? https://codeforces.net/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 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Nice problems

»
3 года назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

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 года назад, # ^ |
    Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится

    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 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится
»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
3 года назад, # |
Rev. 3   Проголосовать: нравится +8 Проголосовать: не нравится

Edit: I see why because of this link: https://codeforces.net/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.