Harbour.Space's blog

By Harbour.Space, history, 3 days ago, In English

Hope you all enjoyed the problemset! Editorials to problems H and I are not ready yet, we will add them as soon as possible. We apologize for weak pretests and easy problems for top participants.

By the way, solution authors did not necessarily prepare the problems. The solutions were chosen at random.

UPD. Editorials for H and I are ready! Wish you all productive upsolving and high ratings!

1553A - Digits Sum

Idea: bthero Preparation: kefaa2

Tutorial
Solution (kefaa2)

1553B - Reverse String

Idea: Errichto Preparation: Will not be revealed for now because we care for his/their safety.

Tutorial
Solution (BledDest)

1553C - Penalty

Idea: Errichto Preparation: BledDest

Tutorial
Solution (BledDest)

1553D - Backspace

Idea: Adel_SaadEddin, Zaher Preparation: Will not be revealed for now because we care for his/their safety.

Tutorial
Solution (Um_nik)

1553E - Permutation Shift

Idea: bthero, kefaa2 Preparation: BledDest

Tutorial
Solution (BledDest)

1553F - Pairwise Modulo

Idea: kefaa2, Errichto Preparation: bthero

Tutorial
Solution (bthero)
Segment tree solution (bthero)

1553G - Common Divisor Graph

Idea: Adel_SaadEddin, Zaher, Errichto Preparation: Errichto

Tutorial
Solution (Errichto)

1553H - XOR and Distance

Idea: kefaa2 Preparation: BledDest, marX, kefaa2

Tutorial
Solution (BledDest)
Alternative solution (BledDest)

1553I - Stairs

Idea: bthero, kefaa2, BledDest Preparation: BledDest, kefaa2

Tutorial
Solution (BledDest)
 
 
 
 
  • Vote: I like it
  • +114
  • Vote: I do not like it

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Harbour.Space (previous revision, new revision, compare).

»
3 days ago, # |
  Vote: I like it +94 Vote: I do not like it

Same in video format: https://youtu.be/NqgObtKz_jM

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

    This is what you want with coffee in the morning.Big Thanks

    • »
      »
      »
      3 days ago, # ^ |
      Rev. 2   Vote: I like it -40 Vote: I do not like it

      https://codeforces.com/contest/1553/submission/123329166

      here is a solution for problem D. since mr um_nik was so fast in solving that he forgot to add editorial

      The code is written in python and should be pretty self explanatory

      EDIT: THANKS FOR REPLY ERRICHTO. I didn't pay attention to the fact that he was a tester

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

        As you can read in the main blog, um_nik was a tester. He has nothing to do with the editorial.

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

          No offence, but I am curious: do you personally like problems B & C? It's very surprising to me that these are the best ideas an LGM, who's also involved in a number of CP activities, can come up with.

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

            No worries, I'm happy to explain my/our reasoning.

            I certainly like B & C more than problem A. In the discussion below some CF blogs, I've already argued that math puzzles aren't that good for easy problems. But yeah, you can also say that I'm getting out of shape and my taste is getting worse. I lost my hopes after feedback from my AGC 47.

            I suggested three easy problems: something rejected as A, penalties without question marks as B, and Reverse String with $$$n \leq 2000$$$ as C or with $$$n \leq 200$$$ as B. I would use those three in my round and I can defend that choice. In particular, I like Penalties most as it's a natural problem that I came up with during Euro Cup. "Given a binary string like 1011100000, say when the winner is already decided".

            Reverse String was rejected because it would be adjacent to the similar-styled Backspace. Penalties were too easy for the second slot (or so we thought) so somebody suggested question marks. Sadly, that change modifies the problem from cute to artificial. Testers then provided feedback that the round is too difficult for beginners. To fit the slot between Digits Sum and Penalties, we used Reverse String with $$$n \leq 200$$$.

»
3 days ago, # |
  Vote: I like it +16 Vote: I do not like it

what is the 85th token of 19th test case of problem D??

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

    If t matches the first few characters of s, you need to judge whether the number of remaining characters of s is even. Only if the number is even can the match be true.

  • »
    »
    3 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    You need to judge if the number of the remaining letters is even or not.

  • »
    »
    3 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Can u give that testcase or something similar to that, I am facing trouble regarding that t-c 19 85-th token..

»
3 days ago, # |
  Vote: I like it +73 Vote: I do not like it

Hey, I am an author of problem F. We actually did not intend any $$$O(N \sqrt{M} \log M)$$$ solutions to pass at the beginning.

The thing is, my Fenwick tree solution works in ~400 ms, but my segment tree solution works in ~2.5 s. Segment tree with pushes does not even pass the time limit because of a high constant factor. Also we had to care about Java solutions, so I decided to raise the TL from 3s to 4s, letting $$$O(N \sqrt{M} \log M)$$$ to pass.

I know I had to fix this problem in a more adequate way by experimenting with constraints. Will certainly do that in future rounds. Sorry about that.

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

    I think you mean $$$\mathcal{O}(N\sqrt{M*\log{M}})$$$ solutions, as I am not aware of any $$$\mathcal{O}(N\sqrt{M}*\log{M})$$$ solution. The thing is, mine was nowhere close even with pragmas and the 64-bit compiler.

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

      My $$$\mathcal O(N \sqrt{M} \log M)$$$ passes pretty comfortably within the TL. Unfortunately, I was not able to debug this quickly enough during the contest.

      Submission

      • »
        »
        »
        »
        3 days ago, # ^ |
        Rev. 2   Vote: I like it +47 Vote: I do not like it

        My solution with a time complexity of $$$\mathcal{O}(N\sqrt M)$$$ passed all the pretests using $$$3400\space\text{ms}$$$ and then passed all the system tests using $$$3416\space\text{ms}$$$.

        Note: this is not a comment talking about creative solutions, but a comment talking about how to use some ordinary data structure to compensate stupidity, so please forgive me if this sounds not so inspiring...... QwQ

        Just sharing some thoughts...... QwQ

        If you use enumerate all of the possible results of $$$\lfloor\dfrac{a_i}{x}\rfloor$$$, you will end up with a condition in which you need to maintain a sequence allowing you to perform to operations:

        • Updating one single element in the sequence(we will simply call this "update").
        • Query the sum of a continuous prefix of the sequence(we will simply call this "query").

        And the length of the sequence is $$$\mathcal{O}(M)$$$, the total number of "update"s is $$$\mathcal{O}(N)$$$, while the total number of "query"s is $$$\mathcal{O}(N\sqrt M)$$$.

        You choose a power of $$$2$$$ near $$$\sqrt M$$$, in my case I chose $$$2^9=512$$$, and divide the sequence into several blocks, each have a length of $$$512$$$.

        You maintain two sequences, $$$C_i$$$ and $$$\Delta_i$$$, in which $$$C_i$$$ means the sum of elements in the $$$i-1$$$-th, $$$i-2$$$-th, ......, and the $$$1$$$-st block, while $$$\Delta_i$$$ means the sum of elements in the $$$i$$$-th position, $$$i-1$$$-th position, $$$i-2$$$-th position, ......, and the earliest position that still belongs in block $$$i$$$.

        It's not hard to see the answer to any queries to position $$$i$$$ is $$$C_{\lfloor\dfrac{i}{2^9}\rfloor}+\Delta_i$$$, meanwhile $$$\lfloor\dfrac{i}{2^9}\rfloor$$$ can be calculated quickly enough using the bitwise >> operation.

        When an update occurs, if the update is a plus $$$x$$$ at position $$$i$$$, you just enumerate all the blocks $$${\lfloor\dfrac{i}{2^9}\rfloor}+1,{\lfloor\dfrac{i}{2^9}\rfloor}+2,{\lfloor\dfrac{i}{2^9}\rfloor}+3$$$,...... and add $$$x$$$ to the $$$C$$$ of those; and within block $$${\lfloor\dfrac{i}{2^9}\rfloor}$$$, you just enumerate all the positions and add $$$x$$$ to the $$$D$$$ of those.

        This data structure handles each update in $$$\mathcal{O}(\sqrt M)$$$ time, each query in $$$\mathcal{O}(1)$$$ time, or constant time, and it also has a pretty excellent constant factor.

        My implementation(may be very ugly QAQ) is here: Submission #123330049 — Codeforces

        Thank you very much for your time reading this! I really appreciate it.

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

          It is amusing that this is kind of a "two-layer" segment tree, and if you change it into three layers, the time complexity handling updates will reduce to $$$\sqrt[3]M$$$ while not changing the time complexity of queries(since its adds up $$$3$$$ pieces of information instead of $$$2$$$).

          That means that you can actually chose ANY constant number $$$\lambda$$$ and make the time complexity $$$\mathcal{O}(\sqrt[\lambda]M)$$$ — $$$\mathcal{O}(1)$$$......

          But in practice I've only seen choosing $$$\lambda=2,3,4$$$ and a large proportion of them $$$2$$$...... QwQ

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

            Shouldn't the complexity be $$$O(\sqrt[\lambda]{M} + M)$$$?

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

              Thanks for your correction, but I meant to say that It costs $$$\mathcal{O}(\sqrt[\lambda]M)$$$ time to use the data structure to handle EACH update operation, and $$$\mathcal{O}(1)$$$ time to use the data structure to handle EACH query operation QwQ.

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

                $$$\lambda = \log n$$$ requires $$$O(\log n)$$$ for both updates and queries.

»
3 days ago, # |
  Vote: I like it -53 Vote: I do not like it

Harbour.space is a ripoff and clearly, this contest sucked. Please downvote the blog to support the cause!

»
3 days ago, # |
  Vote: I like it +8 Vote: I do not like it

Regarding problem E, could someone elaborate on transforming a permutation into another one? Why does the provided algorithm work? Could you provide some online resource about this?

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

    Suppose you have a connected component of size $$$k$$$. It will surely be a cycle. You can easily show that this cycle can be fixed using $$$k-1$$$ swaps, but not less. In total this will sum up to $$$n - cycles$$$ operations.

    Also you could try mixing elements between different cycles, but you will see it does not help either. This is not a formal proof, just a simple explanation built on pure intuition and logic.

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

      Thanks for the intuition. I derived the contradiction of minimality for the case of swapping vertices between two components. And as for the $$$k - 1$$$ swaps, I guess proof is redundant, seems logical to me. :)

      Also thanks to Errichto for his comment.

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

    You need $$$k-1$$$ swaps to transform $$$[1, 2, 3, 4, \ldots, k]$$$ into $$$[2, 3, 4, \ldots, k, 1]$$$. Swapping two values (e.g. the first two) puts one element in proper position. This happens for $$$k-2$$$ swaps and then the last swap puts the last two elements in proper positions.

»
3 days ago, # |
  Vote: I like it -10 Vote: I do not like it

Auto comment: topic has been updated by Harbour.Space (previous revision, new revision, compare).

»
3 days ago, # |
  Vote: I like it -9 Vote: I do not like it

Alternate solution for B

Store all the substrings of the string $$$s$$$ in an unordered map with the string being the key and the value being a vector of ending indices of the substring (note that a single substring might exist multiple times). For the string $$$t$$$, split it into two at every index and let's say we get string $$$t_1$$$ and $$$t_2$$$, check if -

  1. $$$t_1$$$ and reverse($$$t_2$$$) exist in the map
  2. ending position of one such $$$t_1$$$ = ending position of one such reverse($$$t_2$$$) + 1
»
3 days ago, # |
  Vote: I like it +23 Vote: I do not like it

F in chat for person who lost scholarship due to hacks

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

I used a sledgehammer to crack a nut. Used KMP algorithm in B.
My submission: 123364212
Works in $$$\mathcal O(n^2)$$$ probably.

  • »
    »
    35 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Could U give a brief solution on your idea?

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

      In short, I'm searching for all prefixes of $$$t$$$ and reverse of the remaining part in $$$s$$$.

      Spoiler

      Edit:
      1. $$$n$$$ is the length of $$$t$$$.
      2. All searches are done in $$$\mathcal O(n)$$$ as the two substrings to be searched add up to a length $$$n$$$.
      3. $$$0$$$-based indexing is used.

»
3 days ago, # |
Rev. 5   Vote: I like it -6 Vote: I do not like it
»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Dear problem setters please attach images for better understanding of problems !

»
3 days ago, # |
  Vote: I like it +89 Vote: I do not like it

My solution to H is different from the first one provided in the editorial, and the second one provided in the editorial is too vague, so I’ll describe mine here.

Alternate Solution for 1553H - XOR and Distance

Spoiler
»
3 days ago, # |
  Vote: I like it +3 Vote: I do not like it

I think it should be $$$2^{10}$$$ in the editorial of C, instead of $$$2^10$$$.

How to solve B in $$$O(n^2)$$$, I thought a lot but couldn't come up with a solution.

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

    Suppose x is the starting position, y is the rightmost position you covered and z is the leftmost position you covered. For every pair of x and y, z is unique (if it exists)(because length of t is fixed). Now you can easily compare by hashing.

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

    here : 123296482

    some explanation
  • »
    »
    3 days ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    solution i think my dp solution is n2 .correct me if i am wrong.

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

      123306389 my dfs solution is truly similar to yours.I think that the dp array in your solution isn't necessarry and it may not work because we keep going right and then keep going left.So we cannot get repetitive (i,j,flag),right? of course i think our solutions are O(n²) and it may work even faster in tests.

»
3 days ago, # |
  Vote: I like it +47 Vote: I do not like it

TerriblePretestsForces

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

Preparation : will not be revealed for now cuz we care for their safety ...lol .. Btw fstforces

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Wow, problem B was really harder than many people thought.

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

    Not so hard, as $$$\Theta(n^3)$$$ is really easy to think and code.

    Many people thought they can work out $$$\Theta(n^2)$$$ ,but they failed. That's no need.

    • »
      »
      »
      3 days ago, # ^ |
      Rev. 4   Vote: I like it -15 Vote: I do not like it

      But why $$$O(n^{3})$$$ passes as it is $$$500^{3} = 1.25 * 10^{8}$$$ operations but it should be maximum of around $$$10^{7}$$$ per second, right?

      Edit — Found this

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

        it's around $$$2 * 10^8$$$ I think, CF's judging machines are fast, and I think $$$2 * 10^8$$$ is also standard for ICPC

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

        it's not strict n^3 it's lesser than n^3 / 2 and even n^3 alone runs easily under a second

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

        I think it's $$$O(N^3)$$$ because $$$std::string.find$$$ is quadratic in worst case

    • »
      »
      »
      3 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Ya, same happened with me!

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

I had totally ignored bound on m, got that cyclic swaps part during the contest, but screwed all the time by thinking about how can I optimize my solution. Now I have learned from this mistake to read questions carefully :)

»
3 days ago, # |
  Vote: I like it +46 Vote: I do not like it

I think tests on H are weak. I passed them with solution with some stupid approaches + random, but after I looked at the tests I noticed that all big tests have all 1's as answers. Here is the solution that takes random pair i, j and calculates for all x and if n>200 writes all 1's.

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

the pre testcases was weak and made a round not fair for some people i solved a b c d and hacked 6 subbmisions so i was in 1000 place but after main test found d get wrong answer and become in 2200 place it was big shock for me

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

https://codeforces.com/contest/1553/submission/123309155 in this submission i used dp with size 600 but lenth of t maybe equal to 999 why it didnt get run run time error can any one answer me??

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Where is the D?

  • »
    »
    3 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    read um_nik's code and dry run on a few cases u will understand.

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

used brute O(n^3) solution in B. Accepted in PyPy in only 358ms
123296399

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Solution for B: suppose you're standing on the position $$$i$$$. There are 4 cases:

you can go only to the right, so $$$t$$$ is a substring from $$$s$$$.

you can go only left, so the reverse of $$$t$$$ is a substring from $$$s$$$.

you can go right then left, then there are two cases:

either you go from index $$$i$$$ to index $$$i+x$$$: $$$(x >= 0)$$$ then to index $$$i-y$$$ $$$(y >= x)$$$.

then you can divide that into an odd-length-palindrome prefix and some sector, so you take from the center of the palindrome till the end of $$$t$$$. then reverse and check if that is a substring from $$$t$$$.

or you go from index $$$i$$$ to index $$$i+x$$$: $$$(x >= 0)$$$ then to index $$$i-y$$$ $$$(y < x)$$$. then you can divide that into some sector an odd-length-palindrome suffix, so you take from the center of the palindrome till the beginning of $$$t$$$. then reverse and check if that is a substring from $$$t$$$.

If it doesn't belong to any of these options, then the answer is No.

complexity: $$$O(n^2)$$$

link for the submission:
https://codeforces.com/contest/1553/submission/123368933

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

In problem E, can someone provide me a proof why for each cycle of size $$$k$$$ the minimum number of swaps is $$$k-1$$$ ? couldn't it be less than $$$k-1$$$ swap?

  • »
    »
    3 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Proof works with induction.

    The base case is that k==2, then one swap fixes both elements. Else k>2, and swapping two elements fixes at most one of them, leaving us with a cycle of size k-1. It is easy to see that swapping two elements without fixing one does not give a better solution.

»
3 days ago, # |
  Vote: I like it +86 Vote: I do not like it

H can be implemented in a similar style to FFT/FWHT. I don't know if there is a way to interpret this in terms of polynomials.

The code is quite short (shortest submission at time of writing): 123356112. It uses $$$O(k2^k)$$$ time and $$$O(2^k)$$$ memory.

»
3 days ago, # |
  Vote: I like it -23 Vote: I do not like it

actually,i dont think that weak pretest make contest somehow worse.becouse it teach u to be more attentive and re-read code even if it got AC on pretest.And every solution tests on same set of pretests so every one is on equal terms.

  • »
    »
    3 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    So do you submit a solution to A and get pretests passed and then stare at the whole solution till the contest ends, because maybe it will not pass system tests?

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

can some1 help me with B , it is giving me runtime error idk why, https://codeforces.com/contest/1553/submission/123372047

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

    @sa_so_ in both for loops u have used n and n-i But may be in some loop it might be 'm'

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Why can not I see the tutorial of the problem D

  • »
    »
    3 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Because tutorial of D is not available.

  • »
    »
    3 days ago, # ^ |
    Rev. 6   Vote: I like it +1 Vote: I do not like it
    Solution for D

    The tutorial for D is most likely not written yet or its written and is undergoing some edits. Whatever the case, the tutorial is still not out and available yet.

  • »
    »
    3 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Why can not I see the tutorial of the problem D

    My random guess is that maybe the official solution for D was not originally intended to be greedy?

    I first tried to implement my solution as a recursive DP with a two-dimensional state array of 1-bit boolean states, but this is obviously not a good fit for the problem constraints and needed improvements. Still I used this code as a reference implementation to generate a lot of testcases. I thought that maybe a single-dimensional DP state array (storing something like the best index or whatever) could do the job. But then noticed that just a simple greedy modification doesn't seem to fail any of the generated testcases. This was a facepalm moment for me. Spent so much time on something that turned out to have just a greedy solution! The letter D was really deceiving. However observing many system tests failures and hacks after the contest made me change my mind to some extent. The time spent on thoroughly testing solutions locally was not a completely wasted effort after all.

»
3 days ago, # |
Rev. 4   Vote: I like it +16 Vote: I do not like it

I wake up and see result problem D Time limit on test 99 , very sad!!!!!!

  • »
    »
    3 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I have the same problem as you. Have you found where the wrong is? Tell me about it, please.

    • »
      »
      »
      3 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Looking at test 99 I came up with a way to escape the time limit, I check the string s, if the string t contains a character that the string s doesn't, make the word print "no" and return, good luck

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

hello, can you tell me the logic of penalty and why in last test case the answer is 9. It would be helpful if you give me some competitive programming tips. thanks

  • »
    »
    3 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Hello, which problem are you talking about here?

    As for the penalty, For every submission you get a non-AC verdict on tc != 1 during the contest, you get a penalty of 10mins, that is your solution is considered to be 10mins late after the actual AC verdict.

    • »
      »
      »
      3 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I am asking about problem C. Can you help me why is the answer 9 in last test case of problem

      • »
        »
        »
        »
        3 days ago, # ^ |
        Rev. 5   Vote: I like it 0 Vote: I do not like it
        Explaination
»
3 days ago, # |
  Vote: I like it -24 Vote: I do not like it

Looks like whoever prepared the problem, provided the solution.

Does that mean problem $$$B$$$ is prepared by BledDest and $$$D$$$ by Um_nik ?

(Sorry for the mentions)

»
3 days ago, # |
  Vote: I like it +1 Vote: I do not like it

An Easy to understand Recursive Solution of Problem B

bool got(string s, string t, int i, int j, bool goingRight) {
    if (j == t.size()) return 1;
    if (i < 0 || i == s.size()) return 0;
    if (s[i] == t[j]) {
        if (goingRight)
            // then right and left both can be explored
            return got(s, t, i + 1, j + 1, 1) || got(s, t, i - 1, j + 1, 0);
        // otherwise you can go left only
        return  got(s, t, i - 1, j + 1, 0);
    }
    return 0;
}
void argon17()
{
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < s.size(); ++i) {
        // try at every index
        if (got(s, t, i, 0, 1)) {
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}
  • »
    »
    3 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    It's complexity

    • »
      »
      »
      3 days ago, # ^ |
        Vote: I like it -9 Vote: I do not like it

      For each character, we are exploring right as well left characters, so it should be O(n^2).

»
3 days ago, # |
  Vote: I like it +6 Vote: I do not like it

If you have noticed in editorial or not but I found this funny :- Preparation: Will not be revealed for now because we care for his/their safety. :)

  • »
    »
    3 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    i noticed that too.haha i wonder if they will be in danger if their handles are shown?

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Easy to understand C++ implementation of problem B : 123307537

»
3 days ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

When I tried to see the tutorial of problem D, I saw "Tutorial is not available". However, someone has asked a problem about the problem D's tutorial, so if anyone can tell me what's wrong?

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

I tried solving B using two pointers, getting WA on TC 14. Can anyone point out what's wrong? 123384175

»
3 days ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

In D,many codes failed for test 19 ,you guys just have looked the things from back like say you have two strings str1 abd str2 with length n and m respectively. All you need to do is keep a pointer(j) for str2 starting from m-1 coming back to 0 and start iterating for str1 from n-1 (i) if you find such i such that str1[i]=str2[j] and elements which didinot match their count is even then just decrement j and iterate from i-1 .No edge case to be handled in it. You can see my submission,its simple to understand.

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

    can u tell why i am getting wa on test 14 in prob B https://codeforces.com/contest/1553/submission/123345312

  • »
    »
    3 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    my solution was even simpler but had almost the same idea 123325031

    • »
      »
      »
      3 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      This is the solution for D, I am asking for B. I got the idea of O(n^3) approach given in the tutorial, just curious what's wrong with my approach.

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

    A very simple test for D would be the following:

    babcde
    bab
    NO
    

    It is no, because whatever you do, you cannot delete your remaining odd number of symbols(in this case $$$cde$$$) without affecting the other letters, simply because not adding another two symbols requires two(duh), and an odd number is obviously not a multiple of two.

    That's the reason why solutions that worked from 1 to n failed, but those working from n to 1 passed. You can delete as many symbols from the beginning as you like, but this doesn't work for the end, you need to check whether the length from the position of your last taken character till the end of array is an even number. Only then it is possible.

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anybody help me calculate the time complexity of my solution to B? I think it's O(n^4), but it passed the system test. Code here

»
3 days ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

Oops, sorry about that!! Thanks to Nezzar and Rossoneri_Forever!!

»
3 days ago, # |
Rev. 5   Vote: I like it -11 Vote: I do not like it

I have easier solution for problem D , if needed I will explain the code as well

int t ; 
cin >> t ;
while( t -- ){
    string s ;
    string t ; 
    cin >> s >> t ;
    int indx = s.size() - 1 ;
    int test = 1 ;  
    string sk ; 
    for( int j = t.size() - 1 ; j >= 0 ; j -- ){
        for( int i = indx ; i >= 0 ; i -- ){
         if( s[ i ] == t[ j ] && ( indx - i ) % 2 == 0 ){
             sk = sk + s[ i ] ;
          indx = i - 1 ;
          break ;  
          }
        }
    }
    reverse( sk.begin() , sk.end() ) ; 
    //cout << sk << endl ; 
    if( sk == t ) cout << "YES\n" ; 
    else cout << "NO\n" ;
}
»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Great contest from which I learned a lot

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Because I have missed this multiple times in the past and I missed it in E again. So, as a reminder to myself and also for it may help others. These are two other problems which use Constraint Exploitation.

First

Second.

If you know of more such Problems, it would be nice if you could comment them down here.

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

For Problem B, just enumerate all possible turing point (where you change direction), then you will get $$$|a|$$$ strings, which are $$$a'$$$s. Use KMP to query whether string $$$b$$$ is a substring of them, which costs $$$O(|a|(|b| + |a'|))$$$.

Since first step cost $$$O(n^2)$$$, all the problem can be solved in $$$O(n^2)$$$

Code is here: https://codeforces.com/contest/1553/submission/123304298

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

For problem A, if we take n=100 then the possible interesting numbers are 9,18,27,36,45,54,63,72,81,90,99 so there are total of 11 interesting numbers but according to the solution given above the answer would be 10

Can someone explain this anomaly?

Thanks in advance!!

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

    Interesting numbers should be numbers whose last digit is 9, not multiples of 9. So there are 10 in total.

  • »
    »
    3 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    For n=100, the possible interesting numbers are actually 9,19,29,39,49,59,69,79,89,99, which results in the answer becoming 10. other than 9,99 none of the numbers you mentioned are interesting, for example 18 : sum of digits is 9 18+1 = 19 : sum of digits is 10 which violates that S(19) < S(18) and therefore is not an interesting number. Similarly for the other numbers you mentioned. Hope this helped!

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

Deleted. 1001 way to overcomplicate your solution, lol.

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

    Lol.I did the same thing. I initially did 200 times and got an unnecessary TLE because that.

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

123389429 can anyone help me in finding the error in my code for 2nd question

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Harbour.Space (previous revision, new revision, compare).

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

"Preparation: Will not be revealed for now because we care for his/their safety."

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone provide tutorial for Um_nik solution of problem D. It would be really helpful.

Thanks in advanced :)

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

    We first observe that if we type backspace, 2 characters in the origin text will be deleted. If the difference of the lengths between the origin text and the expected text is odd, then we must delete at least one character at the beginning of the origin text (which is what this int p = (n - m) & 1; and for (int i = p;...) does). Then, if the character at s[i] == t[q], we can go and check the next. If not, then we must delete this mismatch. At mentioned at the beginning, we have to delete the both characters starting from the mismatch, which is what the variable k does. Now, at the end, if the index q == the length of expected text m, we have found a way. Otherwise, we cannot transform the origin text to the expected.

    And just saw the official editorial is also avaliable now.

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

in E's tutorial, what does — n/(n — 2n/3) signifies. I count cnt > n — 2m = n/3 why only 3 such counts are possible??

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

    If the sum of many numbers is n, only three of them can be greater than n/3.

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

      Thanks, I will read tutorial again, but can you explain why these 3 value of k are turned out to be only 0, 1, 2, 3?

      • »
        »
        »
        »
        41 hour(s) ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        I don't understand your question. Are you asking about some particular test? You might want to watch the video explanation too, it's in the first comment below the blog.

        • »
          »
          »
          »
          »
          36 hours ago, # ^ |
            Vote: I like it +8 Vote: I do not like it

          I got the solution completely, thank you so much, man...I don't know whether it will benefit me in the future or not to get problems solved using editorials and looking at other's code.

          • »
            »
            »
            »
            »
            »
            36 hours ago, # ^ |
              Vote: I like it +8 Vote: I do not like it

            It will benefit you. Upsolving is much more important than solving problems during the contest.

»
3 days ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Why are they not revealing who prepared certain questions? What security concerns are they worried about? Have there been any past incidents?

»
3 days ago, # |
  Vote: I like it -37 Vote: I do not like it

import java.util.*; import java.lang.*; import java.io.*; import java.math.*;

public class CODEFORCES {

static class FastReader {
    byte[] buf = new byte[2048];
    int index, total;
    InputStream in;

    FastReader(InputStream is) {
        in = is;
    }

    int scan() throws IOException {
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0) {
                return -1;
            }
        }
        return buf[index++];
    }

    String next() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan())
            ;
        StringBuilder sb = new StringBuilder();
        for (; c > 32; c = scan()) {
            sb.append((char) c);
        }
        return sb.toString();
    }

    String nextLine() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan())
            ;
        StringBuilder sb = new StringBuilder();
        for (; c != 10 && c != 13; c = scan()) {
            sb.append((char) c);
        }
        return sb.toString();
    }

    char nextChar() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan())
            ;
        return (char) c;
    }

    int nextInt() throws IOException {
        int c, val = 0;
        for (c = scan(); c <= 32; c = scan())
            ;
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }

    long nextLong() throws IOException {
        int c;
        long val = 0;
        for (c = scan(); c <= 32; c = scan())
            ;
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }

}

public static void main(String[] args) throws java.lang.Exception {
  FastReader sc=new FastReader(System.in);
    int w=sc.nextInt();
    for(int g=0;g<w;g++) {

        String ss=sc.next();
        String tt=sc.next();


        char[] s= ss.toCharArray();
        char[] t= tt.toCharArray();


        int i=0;
        int j=0;


        while(j<s.length&&s[j]!=t[i]){
            j++;
        }
       int ti=-1,tj=-1;
       boolean isdone =false;
       while(j<s.length&&i<t.length){

               if(s[j]==t[i]){
                   ti=i;
                   tj=j;
                   j++;
                   i++;
                   isdone=true;
                   if(i==t.length)break;
               }
               if(ti<t.length-1&&tj>0&&t[ti+1]==s[tj-1]){
                  ti++;
                  tj--;
                  isdone=true;
                  while(ti<t.length&&tj>=0){
                      if(s[tj]==t[ti]){
                          tj--;
                          ti++;
                      }
                      else{
                          break;
                      }
                  }
                  if(ti==t.length){
                      i=ti;
                      break;
                  }

              }
              if(isdone==false){
                  i=0;
                  j++;
              }
              isdone=false;





       }



         if(i==t.length){
             System.out.println("YES");
         }   
        else{
             System.out.println("No");
        }


     }

} }

//This is my Solution of question 2, Getting wrong on test case 14 ,33 token but not knowing why Please can anyone help ?

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

Here is another solution for Problem D: Backspace

Solution

»
2 days ago, # |
  Vote: I like it +5 Vote: I do not like it

Despite several comments mentioning KMP/Z-function as applicable to problem B, I don't see any mentioning that it can actually be solved in linear time $$$O(|s| + |t|)$$$ with that tool.

The basic idea is that the 'turning point' where the chip goes from moving right in $$$s$$$ to moving left must happen in the middle of a palindromic suffix or prefix of $$$t$$$ with some odd length $$$2k+1$$$. The substring of $$$s$$$ visited by the chip in this case is then either the substring of $$$t$$$ without its last $$$k$$$ characters (for palindromic suffixes) or the reversal of the substring of $$$t$$$ without its first $$$k$$$ characters (for palindromic prefixes).

In either case, it is clearly optimal to take $$$k$$$ as large as possible, i.e. use the longest odd-length palindromic prefix or likewise suffix of $$$t$$$. These can easily be found in $$$O(|t|)$$$ with KMP/Z-function, and then the problem is reduced to testing $$$s$$$ for the presence of either of two substrings.

»
2 days ago, # |
  Vote: I like it +8 Vote: I do not like it

I felt like sharing my $$$\mathcal{O}(N \sqrt M + (M + N) \sqrt N)$$$ solution for F.

The basic idea of using the identity $$$a \text{ mod } b = a - b \lfloor \frac{a}{b} \rfloor$$$ and grouping queries by the same values of $$$\lfloor \frac{a}{b} \rfloor$$$ is the same as the tutorial. What is different is that when we are checking the $$$k$$$-th element $$$a_k$$$ we separate in two cases (1) $$$a_k <\sqrt M$$$ and (2) $$$a_k \geq \sqrt M$$$.

We also have an array $$$B$$$ of size $$$\sqrt M$$$ which is updated with the value of $$$x \lfloor \frac{a_k}{x} \rfloor$$$ for all $$$x \leq \sqrt M$$$ on each $$$a_k$$$.

To calculate the sum of $$$a_i \lfloor \frac{a_k}{a_i} \rfloor$$$ for $$$i < k$$$: If (1) $$$a_k <\sqrt M$$$, we just iterate over all $$$a_i < a_k$$$ (as simple optimization, not really needed), and if (2) $$$a_k \geq M$$$, we iterate over values of $$$\lfloor \frac{a_k}{a_i} \rfloor$$$, of which there are at most $$$2\times\lceil\sqrt a_k\rceil$$$.

To calculate the sum of $$$a_k \lfloor \frac{a_i}{a_k} \rfloor$$$ for $$$i < k$$$: If (1) $$$a_k <\sqrt M$$$, we get the value from array $$$B$$$, and if (2) $$$a_k \geq \sqrt M$$$ we query over at most $$$\sqrt M$$$ ranges and sum.

So far, it is not exactly clear how to avoid either having $$$\log M$$$ queries or $$$\log M$$$ updates. What we do now is to separate the array in $$$\sqrt N$$$ groups and update all auxiliary arrays only once for each group. The queries only account for the values of the previous groups, which means that the values missing are of $$$a_i \text{ mod } a_j$$$, for pairs that are in the same group. These values can be recovered offline by checking $$$(\sqrt N)^2$$$ pairs in each of the $$$\sqrt N$$$ groups.

Cool thing about this strategy is that (to my knowledge) it still works if there are repeated values in A.

code

»
47 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

For problem B, we can fix the segment [i,j] which goes from left to right, then calculate k, in that way we can fix the chip's route and then we can use hash to check. The time complexity is $$$O(n^2)$$$.

But I wonder whether we can solve it in an $$$O(n \log n)$$$ or quicker way.

»
44 hours ago, # |
  Vote: I like it +11 Vote: I do not like it

the solution of Problem F may be wrong because it won't print any integer on test 26. Please check your standard solution, thanks.

»
44 hours ago, # |
  Vote: I like it +6 Vote: I do not like it

What's wrong with test #26 of problem F? I don't know why the jury says the length of answer should be 0. I tried some AC codes, but they all get WA on test 26.

»
41 hour(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

Is there a problem with the 26th test point of question f? The code of the person I have used is still wrong. STD can't pass

»
40 hours ago, # |
  Vote: I like it +40 Vote: I do not like it

Unfortunately, the testing on test 26 of problem F was malfunctioning for the last several hours (I don't know the exact reason, probably something with Codeforces cache). The problem is fixed by now, all submissions that failed test 26 will be rejudged in a few minutes.

»
36 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone please tell me why the answer to
cabad
cabac
should be YES for problem B ? (Test case 14).
TIA

  • »
    »
    35 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    If we move the chip position in the order 0, 1, 2, 1, 0 we get cabac.

    • »
      »
      »
      35 hours ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Oh, I can't believe I missed that. I was considering the order 0, 1, 2, 3, and couldn't understand how I could get the 'c' from this. Thank you so much.

»
18 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

A solution for B works in O(n). Use Manacher and KMP. https://codeforces.com/contest/1553/submission/123674097

»
16 hours ago, # |
  Vote: I like it -10 Vote: I do not like it

In problem E I think you mean the sum of cnt[k]= n, not n! This is why mathematicians shouldn't get overly excited (: