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

Автор Vladosiya, история, 19 месяцев назад, По-русски

1729A - Два лифта

Идея: Vladosiya

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

1729B - Расшифруй строку

Идея: MikeMirzayanov

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

1729C - Прыжки по плиткам

Идея: MikeMirzayanov, Aris

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

1729D - Друзья и ресторан

Идея: MikeMirzayanov, Aris, myav

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

1729E - Угадай длину цикла

Идея: Gornak40, MikeMirzayanov

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

1729F - Кирей и линейная функция

Идея: Gornak40

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

1729G - Вырежи подстроки

Идея: senjougaharin, MikeMirzayanov

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

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

Can someone breif me the logic or approach of F??

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

    the value of v(l,r)%9 for anly l,r can be found using string hashing. Now for each l,r query we need to find v(L1,L1+w-1) and v(L2,L2+w-1) but since we need mod 9 hence in total there will be 9 possible valus for each thus in total we can 81 combinations now for each combination check if the condition given is true or not if it is then push the value {L1,L2} in a vector then return the smallest value in the vector.

    Code with comments if u have any doubt do let me know.:)

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

      Great solution, you can also use a tip which can make the code easier. For any number, if the sum of all digits is divisible by 9, then that number is divisible by 9. It works simillar if you want to calculate the remainder. For example: 1233: 1 + 2 + 3 + 3 = 9, and 1233 / 9 = 137. Therefore, you can do the operation using prefix sum. (This operation is also available when dividing by 3)

»
19 месяцев назад, # |
  Проголосовать: нравится +7 Проголосовать: не нравится

finally!

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

can anyone explain the approach of G?? as here the logic was like brute the entire string(smaller one) with it's repetitions in the larger one , but how is the code checking the optimal removal part? also if there is any topic required as a prerequisite in Dp feel free to suggest.

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

Problem E is like if u can't find an optimal solution, use brute force such that it does not give a TLE or go beyond the constraints. We can thereafter prove that our solution is correct at one point because all the other attempts failed and hence we have a higher Probability. So we are correct!

I have learned a new technique and wondered if probability can even be used like this. kudos to the problem setter.

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

    +1. I use binary search ->TLE then tannery search still TLE. Still unable to get the intuition, but still, I find something new to learn. Can you explain the probability concept of the question? (Weak in maths)

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

Code for F is broken, likely because - is automatically converted to — and then to &mdash

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

In D, answer will be 0 and not -1 when no groups can be formed.

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

Can anyone suggest similar problems to E for practice

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

    According to me, this type of problem is not that much productive to solve, instead understanding how probability played a major role in the solution is enough. You can try some interactive problems whose acceptance is completely in your control(not probability) and they are much fun, like this one1698D.

    During the contest, at very start I thought to use binary search, but for the worst case number of query will be Log(10^18)base2, which is something 54-55, then it was obvious for me to try something else and after some tries I figured how to go for the solution, but to be honest, I was ready for a TLE or WA after I'd submitted the solution with probability (1-1/(2^25)), BCZ I'm not that lucky :)

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

    This is a nice problem that uses probability like problem E 843B - Interactive LowerBound

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

    1743D - Problem with Random Tests This is not an interactive problem. But its quite similar because of random testCases

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

For Problem C:

We don't need to iterate to find cost. cost = Math.abs(s[0] - s[n - 1])

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

Very good contest i love all the problem specially E

»
19 месяцев назад, # |
  Проголосовать: нравится +18 Проголосовать: не нравится

There is a small error in E. The probability is slightly smaller than 1/2, since both paths have the same length when dist(x, y) = n/2-1. Which means fixing x and changing only y will give a better probability than changing x and y simultaneously (but still a little worse than 1-2^-25).

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

For problem E it was not very clear from the statement whether interactor assigns answers randomly for ordered pairs (a, b) or not. It could have assigned randomly for each unordered pair, but within same pair (a, b) and (b, a) would not have had 0.5 probability. If that was the case, we would need some other solution.

I've managed to get AC with something like:

  • make first 10 queries to get a rough estimate what n / 2 could not exceed.
  • then at each step pick three random vertices a, b, c and query $$$q1 = (a, b), q2 = (b, c), q3 = (c, a)$$$. Then, $$$q1 + q2 + q3 = n$$$, or $$$q1 + q2 + q3 = 2 * n$$$, or $$$q1 + q2 - q3 = n$$$, etc. But we skip if $$$q_i + q_j = q_k$$$ (even if $$$q1+q2+q3 = n$$$ for this case). Having collected some statistics on the values above among 40 left queries we can also end up with AC.

I don't have formal formulae with probabilities, but at each not skipped step of that algorithm we always contribute one to the answer in our statistic we're collecting, but may also contribute to some garbage values. My guess was that we contribute to garbage less. :)

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

Can anyone please explain approach for G, I am able to find the minimum lenght greedily. Facing difficulties in finding the number.

Thank you in advance for helping

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

We can solve E using binary search. Ln(10^18) ~ 41 or 43 (don’t remember). Use request ? 1 mid, and if answer != -1 then l = mid, else r = mid

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

For problem C, I think there's no need to iterate and calculate the cost. It would be just absolute difference of FIRST and LAST letters.

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

In problem D if no pairs could be formed the answer is obviously 0, not -1.

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

Editorial of editorial of G please.

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

    Notice that we need to maximise the size of the Final string , considering that size of character . is 0.
    Using KMP or String Hashing Algorithm or any other algorithm find out the indexes K, such that s[K-m+1.....K]=t[0....m] , where $$$m$$$ is the size of string $$$t$$$ and push them into vector named $$$ind$$$
    Now make a 2D DP , where DP[i][j] representing number of ways to make prefix of string $$$s$$$ of size $$$i$$$ equal to string of size $$$j$$$ , assuming that . size is 0.
    Now if index $$$i$$$ does not lie in $$$ind$$$, DP[i][j] would be dp[i-1][j-1] , i.e. we take the i'th element of string $$$s$$$ and add it to the final string.
    Else we can take the sum of DP[K-m][j-(i-K)] such that K>i-m and K<=i , where K are the elements in vector $$$ind$$$. K-m represents that all characters of s[K-m+1.....K]='.' , and we substract (i-K) from j because we have already taken all characters in s[K+1.....i]
    Let me know if some part is unclear.

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

      I came up with a 1D dp solution eventually. Your answer inspired me quite a lot, thank you.

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

      If index i doesn't lie in the ind, shouldn't dp[i][j] be equal to dp[i-1][j-1], as dp denotes the number of ways?

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

I don't understand why is E rated 1800? In full honesty, the solution seems so ridiculously easy to come up with. After I thought about it during upsolving, I thought it was so simple that something had to be wrong. After checking the editorial, turns out, nothing was wrong. You really did just have to query pairs a b and b a until you get two different responses.

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

can anyone help why I am getting run time error on test 7 here in problem F

https://codeforces.com/contest/1729/submission/172335851

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

    The number represented in string could be way larger than any build-in type. It's obvious that your convert function can only handle 32-bit integer. Btw I think convert string to integer is not the intention of this problem.

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

In problem E, had it been 60 queries, then we could have find the size of graph by simply applying binary search, right?

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

Can someone give me a hint on problem D?

Thanks in advance.

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

Code chhapne pe idleness limit exceeded nhi aayi, but same code khud krne se aagyi. (Translation: Copying code didn't give idleness limit exceeded, while writing the same code did. Submissions: https://codeforces.com/contest/1729/submission/173058013 https://codeforces.com/contest/1729/submission/173057953 ) Someone comment pls :(

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

Really Liked Question D Glad I was able to solve it on my own, Looked at the editorial code now I think my code is cleaner so in case anybody want to see My Submission