Vladosiya's blog

By Vladosiya, history, 2 years ago, translation, In English

1729A - Two Elevators

Idea: Vladosiya

Tutorial
Solution

1729B - Decode String

Idea: MikeMirzayanov

Tutorial
Solution

1729C - Jumping on Tiles

Idea: MikeMirzayanov, Aris

Tutorial
Solution

1729D - Friends and the Restaurant

Idea: MikeMirzayanov, Aris, myav

Tutorial
Solution

1729E - Guess the Cycle Size

Idea: Gornak40, MikeMirzayanov

Tutorial
Solution

1729F - Kirei and the Linear Function

Idea: Gornak40

Tutorial
Solution

1729G - Cut Substrings

Idea: senjougaharin, MikeMirzayanov

Tutorial
Solution
  • Vote: I like it
  • +50
  • Vote: I do not like it

| Write comment?
»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    2 years ago, # ^ |
    Rev. 2   Vote: I like it +1 Vote: I do not like it

    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.:)

    • »
      »
      »
      2 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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)

»
2 years ago, # |
  Vote: I like it +7 Vote: I do not like it

finally!

»
2 years ago, # |
  Vote: I like it +1 Vote: I do not like it

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.

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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.

  • »
    »
    22 months ago, # ^ |
    Rev. 6   Vote: I like it 0 Vote: I do not like it

    +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)

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
2 years ago, # |
  Vote: I like it +4 Vote: I do not like it

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

»
2 years ago, # |
Rev. 2   Vote: I like it +4 Vote: I do not like it

Can anyone suggest similar problems to E for practice

  • »
    »
    2 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    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 :)

  • »
    »
    2 years ago, # ^ |
    Rev. 2   Vote: I like it +5 Vote: I do not like it

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

  • »
    »
    2 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

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

»
2 years ago, # |
  Vote: I like it +1 Vote: I do not like it

For Problem C:

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

»
2 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Very good contest i love all the problem specially E

»
2 years ago, # |
  Vote: I like it +18 Vote: I do not like it

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).

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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. :)

»
2 years ago, # |
  Vote: I like it +1 Vote: I do not like it

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

»
2 years ago, # |
  Vote: I like it -9 Vote: I do not like it

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

  • »
    »
    2 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    it would take log2(10e18) queries not Ln(10e18) which exceeds 50

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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.

  • »
    »
    2 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Yes, but I think we have to iterate to find the path.

»
2 years ago, # |
Rev. 3   Vote: I like it +1 Vote: I do not like it

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

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Editorial of editorial of G please.

  • »
    »
    2 years ago, # ^ |
    Rev. 5   Vote: I like it +7 Vote: I do not like it

    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.

    • »
      »
      »
      2 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

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

    • »
      »
      »
      2 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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?

»
2 years ago, # |
  Vote: I like it +1 Vote: I do not like it

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.

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

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

  • »
    »
    2 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    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.

    • »
      »
      »
      2 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Ah thanks, misread the constraints, I thought l, r were such that the length doesn't exceed 8

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone give me a hint on problem D?

Thanks in advance.

  • »
    »
    2 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    It's more optimal to have groups consisting in only two people.

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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.net/contest/1729/submission/173058013 https://codeforces.net/contest/1729/submission/173057953 ) Someone comment pls :(

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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