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

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

1312A - Два правильных многоугольника

Идея: BledDest

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

1312B - Bogosort

Идея: Roms

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

1312C - Прибавление степеней

Идея: adedalic

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

1312D - Посчитайте массивы

Идея: BledDest

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

1312E - Сжатие массива

Идея: MikeMirzayanov

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

1312F - Атака на Красное Королевство

Идея: BledDest

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

1312G - Автодополнение

Идея: adedalic и BledDest

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

»
6 лет назад, скрыть # |
 
Проголосовать: нравится -38 Проголосовать: не нравится

fast editorial, thanks!

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

In G we can maintain value "the shortest distance to the smallest line in the lexicographic order from the current prefix" in dfs. To update it just check the distance from the current vertex + 1. And to pass it to the next vertex, we need to add to the value the number of vertices from the S that we went through in other sons. It is O(n). Code.

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

can anyone explain in problem D why we are multiplying by 2^(n — 3) ?

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

    Each element will appear either before the maximum number, or after it. Therefore each of the N-3 numbers (that aren't the maximum and the number we have to repeat) has two options, so we have to mulitiply by 2, N-3 times.

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

    Since there are n elements we are to choose (n-1) elements and one element will be copy of one of n-1 elements choosen by us. Now we can not make copy of max element as it violates the condition so we are left with n-2 elements so we can choose one of them.Let x be the position of max element so the element which has duplicate must be persent on either side because if it will be persent on single side the sequence can not be strictly increasing or decreasing so we have max element at x and two same elements so now we are left with n-3 elements since there are two choices for every element to either go on right hand side of max element or LHS of that max element . so 2^(n-3) factor is involved. why is it so? Since we can arrange a array in strictly increasing order if we dont have duplicates. Hope it was clarified

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

int mul(int x, int y) { return (x * 1ll * y) % MOD; } For what we use this func, why we cant make x-long long, and y-long long, and multiply them?

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

Can anyone please explain E problem it would be great help. Thanks in advance :)

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

    I'll try to go along the lines of the solution:

    Let $$$dp[i][j]$$$ be the value of the single remaining element, when subarray $$$[i:j]$$$ is reduced using the given operation. If there is no way to reduce this subarray into a single element, $$$dp[i][j]$$$ will be $$$-1$$$.

    How do you compute $$$dp[i][j]$$$? Consider index $$$k$$$, such that $$$i \le k \lt j$$$. We divide subarray $$$[i:j]$$$ into two halves: $$$[i:k]$$$ and $$$[k+1:j]$$$.

    Base case: when subarray is of size 1 $$$(i=j)$$$, answer will obviously be the number in that subarray. Now for any $$$k$$$, if $$$dp[i][k] = dp[k+1][j]$$$, i.e. we can divide subarray into two halves such that both halves are reduced to the same number, we can combine the two numbers, hence $$$dp[i][j] = dp[i][k] + 1$$$.

    This is one half of the solution. We now compute the minimum number of partitions that can be reduced to size 1.

    Let $$$dp2[i]$$$ : minimum number of partitions required for array $$$[1:i]$$$. We compute this in this way: Take index $$$k$$$, $$$1 \le k \le i$$$. If $$$[k:i]$$$ can be reduced to a single element, i.e. $$$dp[k][i] \ne -1$$$, then we can find optimal partitioning of subarray $$$[1:k-1]$$$ and just add one to the answer. Formally, $$$dp2[i] = min(dp2[i], dp2[k] + 1)$$$, for all $$$k$$$ such that $$$dp[k][i] \ne -1$$$.

    The required answer is $$$dp[n]$$$. Here's my solution for reference: 72913085. Hope this helped.

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

    Thanks a lot to all in this thread This explanation is much better than that of editorial

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

in problem F, why are five lines enough to determine all the other values?

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

    Let's consider that the number of remaining soldiers is i.Because x,y,z<=5.You only need the answer to[i-5,i-1] to update i.When you know the answer to i,you delete the answer to (i-5),and add the new answer to the end of the vector.In other words,the vector is scrolling. Because the period is at most 36,you can use brute force to find it. I hope this helps. :)

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

Can anyone explain how we get string "ieh" in first example in two seconds? After getting string "i" "ieh" is lexicographically second after "i", so we need at least 3 seconds, isn't it?

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

How to solve problem C using bitmasks. Kindly help me.

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

    You can make each number of the array v into a number based on k.If the number only consists of 0 and 1, it must be able to become 0.Then, mark the position of each 1.If the number consists of other numbers or the position of some 1 is already marked, the array won't be able to be filled with 0 and the answer is "NO". After you finish that operation for each number in the array v, the answer will be "YES".This is my solusion.

    I am a Chinese and I am sorry that my English is poor. if there is something wrong in my words, please tell me and I will repair it as fast as posiible.

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

Is it posssible to solve G on Java?

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

awoo Why the same solutions receive completely different times?:

72925974 4321 ms = 72925981 2885 ms

72927822 1668 ms = 72927856 920 ms

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

Can anyone explain B. Bogo Sort Problem??

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

    In this problem it was quite an observation that if we sort the array in descending(or non increasing order to be precise) then A[i]-i can never be equal to A[j]-j for i<j. Because if i<j that implies A[i]>A[j] since we sorted the array in non increasing order.Now we are subtracting larger value by smaller index example array of 5 4 will become 5-1 != 4-2. hope that helps. Here's the link to my solution

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

    If we sort the array in non-increasing order, then we have

    $$$ \begin{equation} i \lt j \end{equation}\tag{1} $$$

    $$$ \begin{equation} a_i \ge a_j \end{equation}\tag{2} $$$

    Rewrite $$$(1)$$$ to

    $$$ \begin{equation} -i \gt -j \end{equation}\tag{3} $$$

    and add $$$a_i$$$ to both side

    $$$ \begin{equation} a_i - i \gt a_i -j \end{equation}\tag{4} $$$

    Add $$$-j$$$ to both side to $$$(2)$$$

    $$$ \begin{equation} a_i - j \ge a_j - j \end{equation}\tag{5} $$$

    From $$$(4)$$$ and $$$(5)$$$, we have

    $$$ \begin{equation} a_i - i \gt a_i - j \ge a_j - j \end{equation}\tag{6} $$$

    which means

    $$$ \begin{equation} a_i - i \gt a_j - j \end{equation}\tag{7} $$$

    $$$ \begin{equation} i - a_i \ne j - a_j \end{equation}\tag{8} $$$

    $$$ \begin{equation} j - a_j \ne i - a_i \end{equation}\tag{9} $$$

    Therefore, after sorting the array in non-increasing order, for each pair of indexes $$$ i \lt j $$$ , the condition $$$ j - a_j \ne i - a_i$$$ holds.

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

Can anyone explain me C please.

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

Solution for Problem C is not quit clear can anyone help me out with that??? adedalic

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

Could you tell me what does this return dp[l][r] = a[l] ?

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

I have an $$$O(n \log n)$$$ solution to problem E: https://mirror.codeforces.com/blog/entry/74656

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

Can someone please explain how time complexity of problem E is n^3 ? Thanks.

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

    Figured it out after rethinking the problem. Let's think of the main function for loop and calcDP separately. So calcDP is an N^3 function while our for loop runs in N^2. They are independent entities. So when you call calcDP from inside your N^2 for loop, their complexities don't affect each other.

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

There is another solution to problem D with complexity $$$O(n \log P)$$$.

Welcome to see in https://mirror.codeforces.com/blog/entry/74685. For the Chinese version https://andylizf.github.io/2020/03/10/CF1312D-Count-the-Arrays.

Can anyone prove it is equal to the normal solution?

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

Расшарьте Е пожалуйста. Что значит стандартная префиксная динамика? Если это стандартный алгоритм, киньте ссылку пожалуйста, не могу найти.

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

    Там же дальше расписано, что это значит.

    Так или иначе, если стоит задача разбиения массива на несколько отрезков, то кажется очевидным попробовать написать динамику от длины префикса $$$dp[len]$$$ — оптимальное разбиение префикса длины $$$len$$$.

    Переходы тоже прямолинейны — попытаемся перебрать длину последнего блока. И либо добавляем этот блок к текущему оптимальному разбиению, если делаем переходы вперед, либо отрезаем этот последний блок от текущего префикса, если переходы назад.

    • »
      »
      »
      6 лет назад, скрыть # ^ |
      Rev. 2  
      Проголосовать: нравится -8 Проголосовать: не нравится

      Понятно тем, кто уже знает решение, но теперь я кажется понял. Выходит псевдокод будет таким:


      for len in [1, size of array]: if [1, len] can be reduced to one element: dp[len] = 1 else: for i in [2, len): if ([i, len] can be reduced to one) and dp[i - 1] + 1 < dp[len]: dp[len] = dp[i - 1] + 1
»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

can anyone explain c better plz?

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

    The question states that you have an array ( which is initially all zeros ), and you apply some number of operations, say $$$M$$$.

    In $$$i$$$th operation ( $$$0 \le i \lt M$$$ ), you can either pass and go to step $$$i+1$$$, or add $$$k^i$$$ to one of the elements of the array.

    Notice that, each power of $$$k$$$ is used atmost once, if at all. Thus, we simply convert each number to base $$$k$$$, and see if any power of $$$k$$$ is repeated.

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

Another possible solution of 1312E — Array Shrinking. Complexity is O(V * N) where V is limit of a. The solution is here.

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

To solve F, I used the heuristic that the period is equal to $$$smallest+largest$$$ out of $$$x,y,z$$$ It only has 2 exceptions (considering $$$y$$$ and $$$z$$$ equivalent): $$$1,3,4$$$ (period=7) and $$$4,1,2$$$ (period=3).

I have no clue on why this works, wondering if it just somehow worked because of small constraints on the values. Any insights?

Link to my code: 73467272

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

what is the time complexity of D,is it O(m log p) or (n log p)??

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

For problem G,we don't need any data struct .Simple dfs is enough.

The code is very short:

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

In problemA, if we consider case n = 8 and m = 4 then how can a convex polygon with 4 sides can have a same center.

Thanks, in advance

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

    Number the vertex from 0 to n-1 (7) take 0th and 2nd and 4th and 6th vertex

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

      How do you prove that we can have the vertices of smaller polygon in common with larger polygon?

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

        I don't have a math-heavy perfect proof but you can think in this way.

        Lets call polygon of m sides be polygonIn and polygon of n sides be polygonOut. select one side of polygonIn and connect it to the center of polygon the angle will be (2*pi/m) also note that this angle is equal to x*(2*pi/n) (x is some integer) because the end points of a side of polygonIn must be end points of some x continous sides of polygonOut.

        Example in case of hexagon and triangle x = 2 because end points of one side of triangle is also end points of 2 continous sides of hexagon.

        so we get x*(2*pi/n) = 2*pi/m

        x*m = n

        n%m = 0

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

How can we check the period is at most 36 by brute force ?

Is there a theoretical proof for the bound on period ?

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

In problem E, would the single representative of a subarray always be unique (to cache beforehand), would appreciate if someone can give a proof.

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

Can any one help me with my solution (81649940) to Problem E.

my approach :

dp[i][j][0] — min length of which can be obtained from subarray [i,j]

dp[i][j][1]- after reduction of this([i,j]) subarray what is the left most value eg if array is 6 6 3 3 5 then dp[i][j][2] = 7;(from reduced array- 7 4 5)

dp[i][j][2]- after reduction of this subarray what is the right most value eg. if array is 6 6 3 3 5 then dp[i][j][2] = 5;(from reduced array- 7 4 5)

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

    You may get a good answer then you spoil it in the next iteration by this else

    else{
        if(dp[i][j][0]<=dp[i][k][0] + dp[k+1][j][0])continue;
        dp[i][j][0] = dp[i][k][0] + dp[k+1][j][0];
        dp[i][j][1] = dp[i][k][1];
        dp[i][j][2] = dp[k+1][j][2];
    }
    

    Just add a condition to the if above to check if the two ranges are of size 1

    It can be proven that the merged ranges should be of size one each (after reducing)

    Here is my submission 251049164

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

can someone explain me problem C. It would be great help. Thanks

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

resolved

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

can anyone explain Problem A in detail?

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

This tutorial is not linked in the problems, for example 1312A - Two Regular Polygons Maybe someone can fix this.

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

In Problem E, we have the O(n^2) solution that is easier to understand

Here is my code to imple this idea: https://mirror.codeforces.com/contest/1312/submission/102915968

»
20 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

dp 2 makes me feel confused in E

»
16 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I think the example explanation for problem G is not detailed enough.

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

the D is amazing!