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

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

1955A - Акция на йогурты

Идея: mainyutin, разработка: mainyutin

Разбор
Решение

1955B - Прогрессивный квадрат

Идея: ssor96, mainyutin, разработка: Vladosiya

Разбор
Решение

1955C - Обитатель морских глубин

Идея: ssor96, Vladosiya, разработка: mainyutin

Разбор
Решение

1955D - Неточный поиск подперестановки

Идея: mainyutin, Vladosiya, разработка: mainyutin

Разбор
Решение

1955E - Длинное инвертирование

Идея: ssor96, разработка: Vladosiya

Разбор
Решение

1955F - Нечестная игра

Идея: mainyutin, разработка: mainyutin

Разбор
Решение

1955G - НОД на клетчатом поле

Идея: ZergTricky, разработка: mainyutin

Разбор
Решение

1955H - Самая безбашенная оборона

Идея: vmanosin7, разработка: mainyutin

Разбор
Решение
Разбор задач Codeforces Round 938 (Div. 3)
  • Проголосовать: нравится
  • +92
  • Проголосовать: не нравится

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

Thanks for the editorial.

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

Too dumb to understand H

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

Enjoyedd it as always ;)

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

Hacks in problem G were especially too much in this contest Right?

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

    Sorry but I'm a newbie here. How it can be hacked? I do not see any using of hashing

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

      Newbie? Anyways, hacking is when someone finds a counter-example/test which the code fails to answer correctly, on time or exceeds memory limit. Basically, when someone hacks someone's solution/code which passed all tests with "Accepted", they find a testcase following the constraints, however returns wrong verdict when processed by the "solution".

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

Can anyone explain this swap preparation

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

    It often is a good idea to let someone else prepare the problem so that in case mistakes happen in terms of the correctness of the solutions, more people are aware of what is going on.

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

      What does preparation mean in this context?

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

        Create strong test data, alternative solutions and checkers/validators. In this contest, one validator was messed up but it was fixed later on.

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

Thank you for the editorial!

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

Can somebody please tell me why my submission for B 255683892 got TLE in system testing?

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

    Unordered map's worst case time complexity is $$$O(N^2)$$$ due to collisions. Use ordered map for the same.

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

      Thank you.

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

      So should we always use ordered map?

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

        A rule of thumb is to avoid using unordered map whenever you can.

        1. Verify if you can avoid the unordered map by using an array/matrix as a table to index the elements directly. If you can't use directly, sometimes you can normalize the values to make it possible. If the problem has multiple test cases, remember to analyze the complexity to clean up the table between the cases.

        2. If you can't use an array by any reason (memory, hard to code, complexity to clean/reuse...), analyze the worst case complexity with ordered map. If it's clearly enough to pass within the time, then use it. The complexity is more predictable and stable. There is no reason to exchange the "not so fast ordered map, but guaranteed AC" by a "MAYBE faster unordered map, but also MAYBE TLE" during the contest.

        3. If you really need/want to use the unordered map, keep in mind that the test cases can blow up the average unordered map solution, getting TLE sometimes. Hopefully, you can try to avoid this by making some changes in the hash function. You can read more about here: Blowing up unordered_map, and how to stop getting hacked on it

        EDIT: Changed the order and added some explanations.

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

    Just for TLE issue, there are two things you can do to make it run faster:

    1. cin / cout for large amount of data is slow, check here https://mirror.codeforces.com/blog/entry/6251 and use std::ios::sync_with_stdio(false); in your code. You can check samples of other user's submissions to see how they use this to speed up input efficiency.

    2. Don't dynamically allocate arrays in runtime as in int a[n*n], allocate a static array in advance, something like int a[510 * 510] at the beginning.

    I don't believe unordered_map is the issue.

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

      Thank you. But it seems like unordered_map was the issue because I submitted the same solution but with a map instead of an unordered_map and it got accepted.

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

Thank you for fast editorial

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

Is it rated?

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

Is it rated?

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

Can anyone help me with this ? 255764657 getting TLE.. thanks a lot

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

Has anyone solved the problem G with bfs?

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

For C there’s an easier way to think of it: instead of one Kraken, we have two krakens attacking from both left and right, with the left one dealing $$$ceil(\frac{k}{2})$$$ damage and the right one dealing $$$floor(\frac{k}{2})$$$ damage. We can then simulate their attacks independently and count number of ships sunken afterwards.

Code: my solution

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

Problem F has a simple $$$O(1)$$$ mathematical solution: 255716134.

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

    can u elaborate how u come up with this formula

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

      It can be simplified to $$$\sum_{i=1}^{4}\lfloor\frac{p_i}{2}\rfloor + (p_1,\ p_2\ and\ p_3\ are\ all\ odd)$$$. You just have to count states that have zero xor sum, which can be expressed as $$$\vec p = (p_1, p_2, p_3, p_4) = (2n_1, 2n_2, 2n_3, 2n_4) + (n_5, n_5, n_5, 0)$$$ where $$$n_i$$$ 's are arbitary integers

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

      Greedy, first consider $$$n_4$$$, the number of $$$(100)_2$$$, $$$n_4$$$ should be even to make xor = 0, after erasing all number expect $$$(100)_2$$$, the last $$$\lfloor n_4 / 2 \rfloor$$$ sequences have 0 xor.

      Then consider $$$n_1, n_2, n_3$$$, it is evident that $$$n_1, n_3$$$ and $$$n_2, n_3$$$ should have the same parity to make xor = 0. Then you need to try to achieve that by erasing some numbers as shown in the code.

      The optimal solution is: first make $$$n_4$$$ even, then make $$$n_1, n_3$$$ and $$$n_2, n_3$$$ have the same parity, thus one zero-xor is obtained for every two erasing.

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

        Furthermore, ans=\sum_{i=0}^{4}\left\lfloor\frac{p_i}{2}\right\rfloor+\sum_{i=0}^{3}\left(p_i&1\right) 255945388

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

      I come up with similar formula base on the fact that: 1. The result of two XOR elements is 0 if and only if the two elements are equal; 2. The result of three XOR elements is 0 if and only if they are exactly (1, 2, 3); 3. The result of more than three XOR elements is 0 if and only if it can be divided into the sum of the several pairs and triple above. Finally, add a little greedy thought)

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

Could someone explain why BFS TLEs with same logic for G?

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

For problem E, I wonder if there exists some other method to choose&reverse which is better? Or, why always choosing&reversing the first zero from left to right(or right to left) can examine whether a 01-string can be converted to all-1-string. Is there any provements? Thanks a lot.

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

    yaa same doubt

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

      i though something just now, lets take 110.... for example. so now since leftmost one is part of just 1 segment we cant do any operation on this, come to next 1, so due to previous segment there is no change on this 1 and segment starting from this 1 itself is the last one involving this 1 so cant do any operation again, now next 0, so previous segments have no effect. Segment starting from this element is the last one involving it so we have to do operation, no choice and then so on, we will have to take into consideration the operation applied on this zero for next k-1 elements.

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

F — Greedy Approach 255903652

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

What is the rate of problem E could it be below 1400 ?

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

This contest really was not made for python users, most of the solutions were giving tle for python answers and not for the exact same cpp solution

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

why is BFS getting TLE for problem G ?

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

Why I am getting TLE in E? Please help Submission link: 255910548

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

what is the time complexity of this code?? I am. confused about how many factors will be there in a particular state dp[i][j] ?? 255662591

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

    In state dp[i][j] there are only factors which is not divisible by any other factor. The number is hard to calculate

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

Hi, I try to use the logic of dijktra algorithm on porblem G. GCD on a grid.

But, I get wrong answer 2136th numbers differ - expected: '8', found: '4'

I can't figure out the bug: 255917561

Please, help

Thanks

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

    if (-gcds[next_row][next_col]>-next_gcd){ gcds[next_row][next_col]=next_gcd; q.push({gcds[next_row][next_col],{next_row,next_col}}); }

    --> this line is problem like you are ignoring a possible gcd value which cal help you to have transition

    given--> a[i][j] = 6, a[i][j + 1] = 12 but you can do a[i][j] = 10 if you ignore 6 you will get wrong answer

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

    Try this:

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

      max path

      My code output is 2, too.

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

        Okay, so you are doing anti-Dijkstra.

        Then this:

        1
        2 5
        1120 14 14 8 3
        16 08 28 8 8
        

        prints 2, while there is path with 4

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

          Thanks vstiff, I really appreciate

          I think the anti-Dijkstra works, the push into the queue should be outside the if statement, but I get MLE.

          if (-gcds[next_row][next_col]>-next_gcd){
              gcds[next_row][next_col]=next_gcd;
          }
          q.push({next_gcd,{next_row,next_col}});
          

          256041649

          Is there a way to fix it?

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

Why O(N) solution of problem D is giving TLE in python? 255903393

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

    i don't know the full reason but somehow storing strings instead of integers in a dict reduces time ( may be something related to hashing inside a default dict ig) same happened to me i tried just changing int to str dtype in lists of a and b it got accepted. your code's modified submission

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

I dont understand why A* and DFS (with early stopping) give TLE for G. Surely the number of nodes visited is similar to that in the tutorial (effectively doing a search from start to end for each divisor of g)

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

Can someone explain to me how the third example of question F works? I think the answer is 4.

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

    Why do you think the answer is 4? The best case scenario is having the same ones adjacent: 1 1 2 2 3 3

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

how to prove the num of divisor of N is N^(1/3)

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

    Not exactly what the tutorial said, but you can have a look at the function's growth rate.

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

    I don't think so they are trying to say that the number of divisors is N^(1/3), but they are trying to say that the number of divisors is not greater than that. Although for the past 15 mins I was also wondering how is the possible and where is the proof. If someone can explain me in simple terms I would be very thankful.

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

    There were problems about finding the numbers with maximal number of divisors till N, they solved through the backtracking typo generate p_{1}^q_{1}*p_{2}^q_{2}*...*p_{k}*q_{k}, where p_{i} is the i-th smallest number, and the number of divisors is a product of q_{i}+1

    So in generation the most non-trivial thing is to find out that q_{i-1} >= q_{i} because if several numbers with equal number of divisors we are interested in smallest ones, by it you can find that number with maximal number of divisors till 10^9 has 1344 divisors, and till 10^18 has ~1.03e5 divisors, but estimation is clearly rough because 1344 > 1e3

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

Can the twoer located in the enemie's path in the problem H? If it is posiible, why the solution of dp is right?(just one tower has the range of 0?)

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

    By default, all towers have a zero range, but the player can set a tower's range to an integer r (r>0), in which case the health of all enemies will increase by 3r. However, each r can only be used for at most one tower.

    it is mentioned r>0

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

      I know that, but when I use dp, in the final answer, no more than one tower will have the radius of 0. However, when some towers located in the enemy's path, as the promblem says(0 is default), those towers will damage the enemy with zero radius. It seems that the dp can not count this part of damage. Because my dp is weak, I want to konw that whether I misunderstand the problem or the dp can count all zero part in fact.

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

    Towers are located on empty cells

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

Hi guys currently stuck on problem H can't find the problem for this code(wa on test 4). Can anyone help me take a look? Thanks in advance!

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

    Great News guys,got accepted already.

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

    which topic to study for solving this problem

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

      If we're only talking about "TOPICS" then this is a pretty standard bitmask DP problem. However, There's an important observation that the maximum radius of a tower doesn't exceed 12, which LEADS to the method of bitmaskDP.

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

I think in the tutorial of problem F the transition should be dp[i][j][k] =max(dp[i−1][j][k],dp[i][j−1][k],dp[i][j][k−1])+x(i,j,k)

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

For G, why is the number of divisor the cube root of A

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

没有我大中国吗

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

Problem G can be solved using brute force: store the list of gcds at each element and choose the maximum element at point (m,n) https://mirror.codeforces.com/contest/1955/submission/255975752

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

Hey anyone have solved Problem E using Segment Tree??

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

256004789

can someone please explain why am I getting time limit exceeding on test 3? in question C. Inhabitant of the Deep Sea and also tell where I went wrong please ;-;

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

    vector erase is O(n)

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

      could please you tell what I can do instead of erase? and also how I can avoid mistakes like these so that I won't make them during the contests

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

        Because you're only erasing the first and last element, a deque is a perfect ds for that, replace erase with pop_front().

        BTW your solution is also not working, k is 1e15 so obv it will get TLE

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

          ooh my bad silly mistake

          and I did not use deque cause I have not familiarized myself with deques. Thanks I will look into it :> 256015838

          it's still not working is my logic wrong? sorry for so many questions

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

very easy code for F 256008944

if both cnt[1] and cnt[2] are odds, just think them as one for cnt[3]

(01 XOR 10 = 11)

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

Can someone explain to me why my code for G, in which I use DP having a complexity of O(m.n.n) is not working. What I am doing is, I stored dp[i][j] as max gcd from (i,j) to (n,m).

For this, I update the dp as follows:

dp[i][j] = max(dp[i][j], gcd("gcd from (i,j) to (k,j)",dp[k][j+1]))

dp[i][j] = max(dp[i][j], gcd("gcd from (i,j) to (k,j)",dp[k+1][j]))

here is the code https://mirror.codeforces.com/contest/1955/submission/256013095

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

    It's my first approach in the problem but found an easy counterexample for it

    2 3 
    6 2 1
    3 6 4
    

    here ,by maximum $$$GCD$$$ logic, it will outputs $$$1$$$.

    (Since dp[2][2] = max(dp[1][2] = 2, dp[2][1] = 3) = 3 and dp[2][3] = max(1,1) = 1 )

    However, the correct answer here is $$$2$$$ by considering the $$$path$$$

    $$$(1,1)=>(1,2)=>(2,2)=>(2,3)$$$

    P.S:

    The above example is correct in you code, since you start from end

    consider the inverted version of the same example

    2 3
    4 6 3
    1 2 6
    

    your code outputs $$$1$$$, but answer is $$$2$$$ by the same $$$path$$$ described above

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

      Ohhh ok got it. Thanks. How do I know if a DP approach won't work in a program like any tips?

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

        Well, make sure the solution checks all the possibilities. It's convenient to try on small cases first and try to validate your solution on them.

        When you validate your logic, write the slow solution for transition and try to optimize until it fits the time limit.

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

Can anyone help me figure out why my solution to C got TLE? Seems O(n) to me.

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

    your code is O(k), dont subtract a[i] by 1 at a time, you can subtract it by batch

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

https://mirror.codeforces.com/contest/1955/submission/256034339 can anyone give me test case which my code will give wrong answer

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

https://mirror.codeforces.com/contest/1955/submission/256034339 can anyone give test case which will fail my code

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

why vector on E solution??

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

In question G we don't have to iterate through all divisors of g
We can maintain a list of factors
In each loop:
- Choose a search candidate in the list
- If exists a path, discard all values smaller than the candidate
- If not exists a path, discard all values which is multiplier of the candidate
https://mirror.codeforces.com/contest/1955/submission/256059578

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

For problem H, isnt that the enemy only visit certain cells in path, but cover() considers all cells in the range of radius R, right ???

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

    I forgot the fact that enemies will pass thorugh all # cells, i wias thinking in direction where enemies only pass through some # cells, and compilcated my problem..

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

    Thus, the maximum radius for the tower can be found from the inequality $$$500⋅π⋅r^2−3^r>0$$$, assuming that the tower has a damage of pi=500. This estimate gives R=12

    Could you explain how come the Maximum radius is just 12?

    Inequality should be $$$500\times$$$(# of cells)$$$-3^r>0$$$ => $$$500\times (50\times 50-1)-3^r > 0$$$ which gives $$$r=107$$$ right?

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

Can anyone tell why recursion is giving TLE for G? Even if I put this condition that dp[i][j]==true and visited[i][j]==true, return true it still gives tle This

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

Can someone help for the line below:

cout << ans + (dq.size() && dq.front() <= k) << '\n';

What does the (dq.size() && dq.front() <= k) do? What value does it add to ans?

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

    It’s for handling the last remaining element in the deque.

    Dry run the following test case for better clarity:
    5 9
    1 2 3 2 1

    If we didn’t had that line, answer computed by us would be 4 whereas the actual answer is 5.

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

Problem D

My submission 256118405 is getting TLE. Need help.

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

why in the problem G the dp[i][j] = max(__gcd(dp[i][j+1] , curr_num) , __gcd(dp[i+1][j],curr_num))

doesnt work any test case

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

    It seems like you are moving from bottom rightmost cell to top leftmost cell. So your answer would be dp[0][0]

    This is a greedy strategy which will fail for the following test case:
    2 4 11
    2 14 7
    3 2 14

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

I couldn't solve it in contest, but I have queue implementation for problem E in $$$O(nk)$$$ if anyone want an example. https://mirror.codeforces.com/contest/1955/submission/256137527

Same idea, bruteforce for $$$k = n..1$$$ then simulate the flipping. Idea is to maintain the last k indices in $$$[i-k... i-1]$$$ which need to be flipped. The size of this list is same as how many times $$$bit[i]$$$ will be flipped before it. So we'll push $$$i$$$ to queue whenever $$$(bit[i] + size \,\,of \,\, queue) \,\, \% \,\, 2$$$ is $$$0$$$. If there is nothing need to be flipped at the end (queue is empty), then it means $$$k$$$ is possible.

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

Does there exist any solution to problem G using some modification to dijkstra?

I tried submitting a similar approach to dijkstra but it got TLE (on test case 31) because unlike dijkstra, we can't greedily choose the best path with largest gcd for a given vertex and ignore other bad paths with less gcd for that vertex because those bad paths with less gcd further might become good paths. Here's the submission.

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

Millions of people around the world are waiting so kindly stop your personal discussions and focus on others

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

EMJB with kindness offered help and you keep them waiting? Focus on others now!

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

Anyone used binary search for E?

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

Can someone explain me why this submission255752599 is giving WA for TEST-CASE 4 in C

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

In problem G, why does code with 2d arrays for dp work (256666729) and with 2d vectors (256170691) doesn't?

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

A simple mathematical O(1) solution of F: 256693662

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

Damn, prob G we can check divisor of gcd(a11, anm) and check by dfs O(n * m * sqrt(MaxAij)). Enough to AC

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

I want to share an alternative solution for H, which can be solved nicely with a "by-the-book" MCMF implementation:

The key observation is indeed that there are not that many ranges feasible (at most 12). But the fact that two towers can't use the same range may point out the need for a matching kind of approach.

Further, as some choices bring cost (powers of 3) and some are reducing costs (more tiles being covered), then the problem can be modelled as flow graph with:

  • one source
  • K nodes representing the towers (linked to the source, with capacity 1 and no cost)
  • 12 nodes representing the powers of 3 (linked to the towers accordingly, with capacity 1 and the negative cost based on the power of the tower multiplied with the covered tiles using a specific radius)
  • one special node representing that we don't use a power of 3 (i.e. radius 0, linked to each tower, with capacity 1 and no cost)
  • a sink node connected to the powers of 3 (with the cost being the power of 3 and capacity 1) and to the special node (with no cost and an arbitrary large capacity)

Apply MCMF (min-cost, max-flow) algorithm and the answer is the cost straight-away.

https://mirror.codeforces.com/contest/1955/submission/257223979

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

in problem b if i make two matrix and compare them is there any prblem with this approach i am getting wrong on 2nd test case 257477711 .

somebody help

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

i don't understand the solution of Question F

mine look so simple and faster

any explain for editorial solution of Question F ?

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

import java.util.*; import java.lang.*; import java.io.*;

public class Main { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ int n = sc.nextInt(); int m = sc.nextInt(); int x = sc.nextInt(); int[] a = new int[n]; Map<Integer,Integer> b = new HashMap<>(); for(int i=0;i<n;i++){ a[i] = sc.nextInt(); }

for(int i=0;i<m;i++){
            int k = sc.nextInt();
            b.put(k,b.getOrDefault(k,0)+1);
        }

        int i = 0;
        Map<Integer,Integer> window = new HashMap<>();
        int res = 0,c = 0;
        while(i<m){
            int k = a[i];
            window.put(k,window.getOrDefault(k,0)+1);
            if(b.containsKey(k) && window.get(k)>=0 && window.get(k)<=b.get(k)){
                c++;
            }
            i++;
        }
        if(c>=x)res++;
        while(i<n){
            int f = a[i];
            int l = a[i-m];
            window.put(l,window.getOrDefault(l,0)-1);
            if(b.containsKey(l) && window.get(l)>=0 && window.get(l)<b.get(l)){
                c--;
            }
            window.put(f,window.getOrDefault(f,0)+1);
            if(b.containsKey(f) && window.get(f)>=0 && window.get(f)<=b.get(f)){
                c++;
            }
            if(c>=x)res++;
            i++;
        }
        System.out.println(res);
    }
}

}

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

Can someone elaborate why G has a time complexity of O(n*m*cubic_root(A))? I think it's O(n*m*sqrt(A)).

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

https://mirror.codeforces.com/contest/1955/submission/259734054 on test: #2 wrong answer expected NO, found YES [122nd token] What did i do wrong here? can anybody figure it out?

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

B

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

Can anyone tell why the following code for the problem G ~~~~~ Your code here... ~~~~~

1955G - GCD on a grid gives wrong answer 259895161

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

    The solution and the idea is wrong, you don't take gcd with dp values you take gcd of path (i.e the values given in the grid). Here you are taking $$$dp[i][j]$$$ = $$$max(dp[i][j], gcd(dp[i-1][j]/dp[i][j-1], a[i][j]))$$$ in this $$$dp[i-1][j]/dp[i][j-1]$$$ is storing max values instead of $$$(a[i-1][j] / a[i][j-1])$$$ you are taking gcd of max value and current value instead of $$$gcd(a[i-1][j]/a[i][j-1], a[i][j])$$$ which is wrong.

    Hint for correct solution:

    Hint-1

    Hint-2

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

D have a little strange

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

Thanks for the editorial.