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

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

1027A - Палиндромная замена

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

1027B - Числа на шахматной доске

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

1027C - Прямоугольник минимальной стоимости

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

1027D - Охота за мышью

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

1027E - Противоположная раскраска

Разбор
Решение (PikMike) O(n^3)
Решение (BledDest) O(n^2)

1027F - Сессия в БГУ

Разбор
Решение (Vovuh)
Решение (Vovuh) Алгоритм Куна

1027G - X-мышь в общежитии

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

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

You don't need a binary search in problem F. The complexity is O(nlogn) for coordinate compression. Build the graph, then apply DSU or SCC(Tarjan or Korasaju) with do the job. If there exists a connected component with number of edges greater than the number of vertices, then the answer is -1. If the number of edges is equal to the number of vertices, record the largest value, If the number of edges is equal to the number of vertices minus one, record the second largest value, the answer is the maximum over all connected components.

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

Can you please elaborate on the part of partial sums in problem E to solve the problem in N^2 time. I am unable to get it.

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

    let lte[i] be the n.of binary strings of length n such that maximum segment of a single color has length <= i. (lte[i]-lte[i-1]) will be the n.of binary strings of length n such that maximum segment of a single color has length = i. Hence if we have lte array we can solve the problem. We can calculate lte[i] in O(n) as follows. let dp[j] be the n.of binary strings of length j such that maximum segment of a single color has length <= i.

    If j>i dp[j]=dp[j-1]+dp[j-2]....dp[j-i]

    else dp[j]=dp[j-1]+dp[j-2]..+dp[1]+1.

    This is because in a string of length j at the beginning we can have at most i bits with the same color and after that, it's just dp[remaining length]. Now, lte[i]=dp[n]. Clearly, we can calculate the dp array by using partial sums in O(n). Since each element of the lte array takes O(n) time to calculate overall complexity is O(n^2). P.S: Don't forget to multiply by 2 at the end since all this is for a fixed color of the top left tile and it has 2 options (white or black).

    AC: O(n^2)

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

Не должны ли переходы в задаче E быть такими:

dp[i][j + 1][max(j + 1, k)] +  = dp[i][j][k] и dp[i][1][max(1, k)] +  = dp[i][j][k]?

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

Can someone find out what is time complexity on my code? (problem C)

Here is my code 41811657 I think it should be O(T*n*log(n)) . But why it got TLE in case 6. Thank you!!

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

What does this line do in the code for Problem E? ans = (ans * (long long)((MOD + 1) / 2)) % MOD; Edit : Understood. For anyone having trouble it is modular inverse

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

Kuhn's algo for F works only with this particular modification found in your solution -- you first check all the edges and if you find a suitable one, then you use it. Only if there are no suitable edges found, then you do a second loop and recurse into them (DFS). This versions passes tests. I don't know why.

However, a "vanilla Kuhn" that just uses a regular DFS (tries every edge to a non-visited vertex recursively) receives TLE, which is kind of expected, since it has complexity O(N*M) -- too big for this problem.

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

I've sent a solution for C (after the end of the contest) which sounds precisely like the given here (41817149), but it still didn't fit into given time :( What did I do wrong?

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

In problem D, Why it is better to put trap on cycle, although there may be cheaper way to put trap on each path leads to this cycle like that. https://drive.google.com/open?id=19ff-GgeGhbhGXh5MykElhYXB3EErpq_9

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

    Because we don't know where the mouse starts (it may start in any vertex). Mouse can be on a cycle at the beginning and if the mouse is on a cycle at the beginning, it will be on this cycle forever. Thus it is necessary to put a trap on cycle, otherwise mouse beginning on cycle will never be caught. And according to your example, if we put a trap in vertex with cost 100, mouse will go through this vertex regardless of its beginning vertex, so it is enough to put there a trap.

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

As far I know Complexity of Kuhn is O(n * n). How F is Solved with Kuhn? What's the trick or am I wrong? Thanks in advance.

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

Problem G: How to prove there is exactly u that u * x = v?

Help me. Thanks.

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

can someone help me in visualization of problem E dp.

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

A little help on problem C! I don't know what I am doing wrong. I have a code in Python similar to the above solution, and I got TLE on test 5. Here is my code : http://mirror.codeforces.com/contest/1027/submission/41941233 Can someone find out?

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

In problem D, the editorial says that the mouse will stuck in a cycle. But my question is that, should the vertex in the cycle be reachable from all other nodes which are not part of the vertex's cycle because the girls are not aware of the position of the mouse? If it is required the how can we find it?

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

can someone please provide links to understand kuhn's algo?

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

Can anyone help me find the complexity of my code..?for Problem D...THis is my code in java.. http://mirror.codeforces.com/contest/1027/submission/42027693 Thanks

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

sorry ignoring my algorithm (i mean whether is it correct or not) why i am getting TLE on test 2 ty 42082971

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

Problem D:

Why does the mouse jump on a cycle at some point, no matter the starting vertex ?

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

https://mirror.codeforces.com/contest/1027/submission/41811657 can someone tell me why I am getting tle my method is almost same as that it tutotrial

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