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

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

1217A - Создавая персонажа

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

1217B - Змей Горыныч

Идея: Roms

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

1217C - Количество хороших подстрок

Идея: Roms

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

1217D - Покраска ребер

Идея: BledDest

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

1217E - Запросы суммы?

Идея: BledDest

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

1217F - Задача с обязательными онлайн-запросами

Идея: BledDest

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

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

Thank you very much for the round!

In E, it's said:

The problem now got reduced to: find a pair of numbers $$$a_i$$$ and $$$a_j$$$ such that $$$l$$$ $$$ \lt =$$$ $$$i$$$ $$$ \lt =$$$ $$$j$$$ $$$ \lt =$$$ $$$r$$$, there is at least one position such that both $$$a_i$$$ and $$$a_j$$$ have non-zero digits on it and $$$a_i$$$ $$$+$$$ $$$a_j$$$ is minimal possible.

Shouldn't $$$i$$$ and $$$j$$$ imply $$$i$$$ $$$!=$$$ $$$j$$$?

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

Мне кажется, в D легче заметить, что каждое ребро либо не встречается ни в 1-ом цикле, либо только в 1-ом цикле. Из этого следует, что минимальное кол-во цветов в раскраске либо 1(если нету циклов), либо 2(если есть циклы). Получается, что нам нужно просто найти все циклы в графе и покрасить в каждом из них любое ребро в цвет 2.

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

why is the bound from problem D so low? the solution should be in $$$O(n)$$$?

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

    i'm not sure, but the checker may have a higher asymptotic time complexity, $$$O(n^2)$$$, for example

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

      the checker will create a graph with edges of a single color (at most two graphs) and do a toposort on each of them to detect cycles. Therefore the checker is in $$$O(n+m)$$$ and can also handle much larger inputs

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

    I think in general when you're setting problems, you should strive to exclude all the naive solutions, but let certain solutions pass. However, if possible, you should try not to give away desired complexity with the bounds, because that makes the problem easier. Usually, this second part is not possible because CF has a lot of problems where O(n^2) is naive and O(n) or O(n log n) is optimal, so any MAXN less than 10^5 will let O(n^2) solutions pass.

    However, here, the naive solutions are in the exponential range, and there aren't really any "bad" quadratic solutions, so I think it's okay to leave the bounds there so that it doesn't give anything away about the solution.

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

here is written if r-l>18 then f(l,r)>2*10^5.and why? example: 00000000000000000000000000001. it's obvious that that binary number is 1.

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

While solving A by fixing the condition on minAddI, I get WA.

minAddI = ceil((str+exp-int-1)/2)
ans = max(0, max(minAddI+1))

What's the mistake here? Can't we look at the various ways of points to be added for Intelligence?

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

can somebody explain me problem c? you can write short answer, but bigger is better :D

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

Can somebody explain B? How does the formula come? I think sorting on the basis of difference is enough. After sorting we just have to see the first element, isn't?

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

    if max damage >= head, you only need 1 hit if it's not and max ratio pair of damage and regen <= 0, you wont be able to win

    lastly, you know you need to deal x times max ratio pair of damage and regen + 1 times using max damage to finish, so the answer will be x + 1 ( 1 times using max damage).

    • (x * ratio) + max damage >= head
    • x >= (head — max damage) / ratio
    • remembers, x can be floating number here, and we need to round it up
    • so, you can add 1 to x if (head — max damage) % ratio > 0
    • or you add the divisor — 1
    • x >= (head — max damage + ratio — 1) / ratio
»
7 лет назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

Another way to color edges in problem D. Neither simpler nor harder but just another XD.

Let's iterate over all vertices and color all "$$$in$$$" edges in color $$$1$$$ and "$$$out$$$" edges in color $$$2$$$. For every cycle, there will be the vertex which was considered last in it (let's call it $$$u$$$). It implies that color from the previous vertex in the cycle to $$$u$$$ and color from $$$u$$$ to the next vertex in the cycle are different.

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

Does anyone know how to solve F in LCT implementation?

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

can you explain c? such algorithm does not support substrings like 00000000000001, because there hightest position is 13 and lowest 0, i don't understand please explain to me

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

I have a doubt in E, in the proof that an unbalanced set can never be made balanced again. Where are you using the assumption that $$$a\subset b$$$ ?.

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

    We've made some set unbalanced by having two numbers with non-zero digits at some position — that's the set $$$a$$$. So now we can always find such a position in the set $$$b$$$.

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

Another easier approach to problem D:

Suppose a graph $$$ G = (V, E) $$$. Partition $$$ E $$$ to one group contains $$$ in \gt out $$$ only, and one group contain $$$ out \gt in $$$ only. Clearly no cycle in two sets. So the maximum number of colour is 2. One can just check if 1 colour is OK.

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

Can someone explain me why my code to F with block = 500 gets AC, but with block = sqrt(n) + 10 gets WA? https://mirror.codeforces.com/contest/1217/submission/60218374, https://mirror.codeforces.com/contest/1217/submission/60218188.

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

You missed a trivial solution to D: If there's a cycle, paint each edge $$$(u,v)$$$ such that $$$u \gt v$$$ black and all others white.

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

    Nice solution! Actually I think that this is almost the same as the one in the editorial. Just that I don't like the complicated proof that was presented.

    I think that we can easily prove that your solution works because if we consider the indexes of nodes that are in a cycle, there will obviously be a distinct maximum and minimum index because there are at least 2 nodes in a cycle.

    The predecessor of the node with max index clearly has a smaller index. This means that we have an edge (u, v) where u < v. The predecessor of the node with minimum index clearly has a larger index. This means that we have an edge (u, v) where u > v.

    Therefore, in any cycle, we will always have an edge (u, v) where u > v and an edge (u', v') where u' < v'. In this way, we will always have at least one black and one white edge in a cycle.

    I believe this proof works for the official solution as well.

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

Why I got TLE in E,my solution is only O((n+m)⋅logn⋅log10MAXN).link

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

In problem C why we are doing precalculation of nxt array?? can someone elaborate this?

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

    I'm not sure I understand the editorial solution either, but I coded up a simple brute-force / two pointer solution with a pruning heuristic: 60334519

    To summarize, we iterate through the string from left to right. If $$$s[i] = 0$$$, we increment a $$$len$$$ accumulator and move on. If $$$s[i] = 1$$$, we start a secondary loop, where we keep track of the potential values of $$$f(z,j)$$$ (where $$$z$$$ is an imaginary pointer $$$\leq i$$$ that includes the "streak" of $$$0$$$s just before this $$$1$$$ if it exists). $$$ans$$$ is incremented whenever $$$f(z,j) \leq len(z,j)$$$ since it means we have found a good substring (you can "cut" a substring of the right length), but as soon as $$$f(z,j) \gt len(z,j)$$$ no more good substrings can be found from this position as $$$f$$$ grows faster than $$$len$$$, so we cut off the search and reset $$$len$$$ before moving on. Since the inner loop will never iterate more than $$$\lfloor \log_2 n \rfloor + 1$$$ times before being cut off, the algorithm runs in $$$O(n \log n)$$$ time.

    Edit: Actually it might be in $$$O(n)$$$ time, because an adversarial input can only force more inner loop iterations by including zeros before the one, but zeros don't trigger the inner loop, and increasing the number of zeros has rapidly diminishing returns

    Edit 2: Just noticed that toshinaritong explained a similar solution

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

      Can you please elaborate how can we cut a substring of right length if f(z,j)<=len(z,j)

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

        $$$f(z,j) \leq len(z,j) \Rightarrow \exists! x : z \leq x \leq i \land f(x,j) = len(x,j)$$$, i.e. substring $$$x..j$$$ is "good".

        In less formal terms, the indices between $$$z$$$ and $$$i$$$ indicate the "pool" of zeros we can use to manipulate the length of the substring; as long as $$$f(z,j) \leq len(z,j)$$$ we can always choose to include the exact number of zeros required for the substring to be good. When $$$f(z,j) \gt len(z,j)$$$, we don't have enough zeros, so we break the inner loop and move on.

        Or in more concrete terms, take the example $$$s = 00001010$$$

        When $$$i = 5$$$ (one-indexed), $$$z = 1$$$. Since $$$s_5 = 1$$$, we start the inner loop.

        When $$$j = 5$$$, $$$f(z, j) = 1 \leq len(z, j) = 5$$$. Pick $$$x = 5$$$. Note that substring $$$5..5$$$ is good cause $$$f(5, 5) = 1 = len(5, 5)$$$

        When $$$j = 6$$$, $$$f(z, j) = 2 \leq len(z, j) = 6$$$. Pick $$$x = 5$$$. Note that substring $$$5..6$$$ is good cause $$$f(5, 6) = 2 = len(5, 6)$$$

        When $$$j = 7$$$, $$$f(z, j) = 5 \leq len(z, j) = 7$$$. Pick $$$x = 3$$$. Note that substring $$$3..7$$$ is good cause $$$f(3, 7) = 5 = len(3, 7)$$$

        When $$$j = 8$$$, $$$f(z, j) = 10 \gt len(z, j) = 8$$$, so we break the loop and continue iterating $$$i$$$.

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

Problem E. While updating, why don't we consider the case when a[pos] was the minimal number with non-zero j-th digit in the interval [l,r), and x > a[pos]?

For instance we have the array [1,2] and we're getting the update query with pos = 1, x = 5. When updating, t[v] for [1,2), min_digit[0] still will be 1, but it should be 5.

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

Can someone please help in problem D.

I am using the concept of back-edge only, If I found a back edge, color it with '2', else 1.

My solution: https://mirror.codeforces.com/contest/1217/submission/60415966 Its based on this article: https://cp-algorithms.com/graph/bridge-searching.html

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

There's something weird with problem F. I got accepted with 748ms by setting P=5*10^4. If I use P=sqrt(m), my submission receives TLE verdict. What is going on?

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

I am getting a TLE on test case 5 for problem E — Sum Queries. Can someone tell me how to make my solution faster ? 62117228

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

can i do the same in problem d as in the editorial, but instead just make the first edge of a cycle into a second color, all the others edges are the first color? if im not mistaking the logic of the proof of my solution is the same as authors solution, but my solution gets wa3. can someone tell why approach with first edge in cycle is not working, or its working and my implementation is bad submission

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

I think setting such TL in problem E is stupid. I don't care about cache-friendliness or whatever. If my solution has the right complexity, it should pass.

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

For the above case(problem D), a cycle is possible with black edges. Black ones are black edges and purple edges are white edges. Visiting order of DFS is 1, 2, 3, 4, 5. If I'm missing something, can anyone say what is it?

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

basic binary search solution for problem A: 350684495