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

Автор awoo, история, 5 лет назад, По-русски

1107A - Разбиение последовательности цифр

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

1107B - Цифровой корень

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

1107C - Brutality

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

1107D - Сжатие

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

1107E - Вася и двоичная строка

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

1107F - Вася и бесконечные кредиты

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

1107G - Вася и максимальный заработок

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

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

Someone help with the solution for problem-B. I can't "easily" get it :( How did it go from the formula to (k−1)⋅9+x

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

Problem G:
For every diff[i], I calculated the range in which it is maximum and took maximum suffix from left side and maximum prefix from the right side to calculate the answer.
Before constructing the segment tree,just to verify the logic I submitted the code with O(n) function to calculate max prefix and suffix expecting a TLE, but surprisingly it got ACed. Submission: 49068594
Are the test cases weak or is the time complexity of this solution lesser than O(n^2)
EDIT: neal answered it here

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

For problem D, the brute force solution apparently runs fast enough.

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

    Yes,my brute force solution runs for 800+ ms.So I don't think this problem is very good and I don't know why this problem's difficulty is 1800. The time complexity just O(n²*c) ,c is the number of divisors of n

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

On the one hand, if some segment of kind [1+lx , 1 + (l+1)x], where l is the value from the range [0;n/x−1], contains different digits then we cannot compress the given matrix.

Can someone explain me this with an example ??

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

    Please.. Someone explain me this with an example too.

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

    for example:- let us assume that the size of given matrix A is 8 and we are using x = 2, then values of Ceil(8/2) = 4,Ceil(7/2) = 4 which means B[4][4] is equal to A[8][8], A[7][8], A[8][7],A[7][7]. which will not be possible if these values are different.

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

Problem G: Solved it using segment trees(max segment tree) and lazy updates. Start iterating i from 1 to n. For a fixed i, a node j(<=i) will contain the answer for the segment j to i. So at each iteration, make a query from 1 to i. For the update part, when going from i to i+1, add (a — c[i+1]) to the range (1 to i) and maintain a stack to store the gap values for the range. For the stack update, if the new value i.e. (d[i+1] — d[i])^2 is smaller than the top value of stack, just add the negative value of it to the stack with it's range and also update it's value in the segment tree. If the new value if larger than the top value of stack, keep popping the top value(these values also need to be updated in the segment tree) until the new value is smaller than the stack's top value. Submission: 49103066

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

Why additional time is not given for Java programmers? Even the solution given in editorial for problem D is giving TLE in Java.

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

In task F we don't have to pick every credit, so shouldn't the formula be min(0, rest of formula)? Every Hungarian algorithm (that I found) assign all of n elements. Or just b[i]*k[i]<=a[i], but the statement doesn't include it?

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

Regarding the tutorial for problem E.

I think it should be l ≤ mid ≤ r instead of 1 ≤ mid ≤ r here.

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

    also mid<=r only if cnt=1

    • »
      »
      »
      5 лет назад, # ^ |
        Проголосовать: нравится +1 Проголосовать: не нравится
      dpdig, l, r, cnt = max{ansl, mid - 1 + dpdig, mid + 1, r, cnt - 1}

      what is the difference between these two?

      dpdig, l, r, cnt = max{ansl, mid - 1 + dpdig, mid, r, cnt}

      i mean is there something wrong with the second one?

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

Someone please explain the solution for problem-E, I didn't understand it from the tutorial.

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

    Made a solution just doing recursion on strings to show the idea (solution). I think this is a bit easier to follow.

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

      Nice Approach, I tried this and got AC, but before that I had tried to recursively remove each block of consecutive digits(same 1s or Os). Algorithm is right but I got TLE, I don't understand why it is. Can you explain what happen? HERE IS MY CODE: https://codeforces.com/contest/1107/submission/49218582

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

        The difficult part of this problem is not really to calculate the answer but to do it quickly. The reason why my code doesn't get TLE is that I practically only modify the beginning of the string, and if you think about it all the strings that is created will basically be a substring of the original string (except for the beginning part). So the number of strings I create are very limited.

        In your code you are not doing it nearly as neatly because you are deleting parts of the string everywhere (not just in the beginning). So you will create a ton of different strings, probably exponentially many, and because of that get TLE.

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

          Yeah I understand your code, that is your state either is substring of original string or combination of two substrings of original string. The number of different substring is nC2 ~ N^2 and the number of combination of 2 substrings is (N^2)C2 ~ N^4, so your complexity is O(N^4).

          And my code may be up to N! So it gets TLE.

          Thanks for your help!

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

            To be technical, its not either a substring of the original or a combination of two substrings. It is always a string on the form '0...0' + S[a:b] or '1...1' + S[a:b] so there are n3 possible different strings.

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

              Yep, sorry. So it runs in N^3 right?

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

                The algorithm will ever only visit n3 strings but for each string it will do at most n2 work. This is because for each string it might need to lookup n strings in a hashtable. So it runs in n5 with a very good constant, this could be lowered to n4 by playing around with indices instead of strings.

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

For Question B Digital root,We an use S(x)=x mod 9.

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

I will give a proof in this comment on why the formula for 1107B - Цифровой корень works.

To see that the formula is true you can prove that and gives the same value or it is invariant under the formula. In the case of xj substracting 1 means that the trailing 0s become 9s so the disappear modulo 9 and if k is the first non-zero digit of xj then its value will decrease by 1. Then we can do something like this:

It's not hard to see that given a b-ary number system where b is a positive integer if we define a similar process then the number x will end up in Sb(x) which can be characterized like:

The proof is the same as the above just replace 10 with b and 9 with b - 1.

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

good

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

Can someone please explain the editorial of E in more detailed way ?

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

Can someone explain why DP calculation in E is correct i.e. why there exist 'mid', why optimal solution for DP doesn't contain more than one segment which will lead to 'cnt' number of 'dig' instead of just a segment [mid, r]?

Upd: Got it.

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

In D why can't we use binary search on divisors of n to find max value of x

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

vovuh In D why can't we use binary search across the divisors of n to find x?

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

    Because the function isn't monotonic. For $$$n=12$$$ if the answer for $$$2$$$ and $$$4$$$ is true then it is not necessary that for $$$3$$$ the answer also will be true.

    Example (uncompressed):

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

A different approach for problem D here

Using gcd

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

Whosoever solves problem E.

Please let me know how the complexity of the solution is O(n^4).

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

For Problem G: I used Kadane's algorithm but it gives wrong answer on test 7 and test 36 only. Could anyone point out the issue with this approach. Code with some comments.

»
22 месяца назад, # |
  Проголосовать: нравится -10 Проголосовать: не нравится

Simple bruteforce is enough for 1107D — Compression. https://codeforces.com/contest/1107/submission/160440328