Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

### Harbour.Space's blog

By Harbour.Space, history, 18 months ago,

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: 244mhq

Tutorial
Solution (kefaa2)

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, 244mhq Preparation: BledDest

Tutorial
Solution (BledDest)

1553F - Pairwise Modulo

Idea: 244mhq, Errichto Preparation: bthero

Tutorial
Solution (bthero)
Segment tree solution (bthero)

1553G - Common Divisor Graph

Tutorial
Solution (Errichto)

1553H - XOR and Distance

Idea: 244mhq Preparation: BledDest, mnaeraxr, 244mhq

Tutorial
Solution (BledDest)
Alternative solution (BledDest)

1553I - Stairs

Idea: bthero, 244mhq, BledDest Preparation: BledDest, 244mhq

Tutorial
Solution (BledDest)

• +134

| Write comment?
 » 18 months ago, # |   0 Auto comment: topic has been updated by Harbour.Space (previous revision, new revision, compare).
 » 18 months ago, # |   +94 Same in video format: https://youtu.be/NqgObtKz_jM
•  » » 18 months ago, # ^ |   +30 This is what you want with coffee in the morning.Big Thanks
•  » » » 18 months ago, # ^ | ← Rev. 2 →   -40 https://codeforces.com/contest/1553/submission/123329166here is a solution for problem D. since mr um_nik was so fast in solving that he forgot to add editorialThe code is written in python and should be pretty self explanatoryEDIT: THANKS FOR REPLY ERRICHTO. I didn't pay attention to the fact that he was a tester
•  » » » » 18 months ago, # ^ |   +19 As you can read in the main blog, um_nik was a tester. He has nothing to do with the editorial.
•  » » » » » 18 months ago, # ^ |   +54 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.
•  » » » » » » 18 months ago, # ^ |   +54 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$.
 » 18 months ago, # |   +16 what is the 85th token of 19th test case of problem D??
•  » » 18 months ago, # ^ |   +23 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.
•  » » » 18 months ago, # ^ |   +6 yaa, i missed it. thanx bwxnQAQ Now you are my friend.
•  » » 18 months ago, # ^ |   0 You need to judge if the number of the remaining letters is even or not.
•  » » 18 months ago, # ^ |   0 Can u give that testcase or something similar to that, I am facing trouble regarding that t-c 19 85-th token..
•  » » » 18 months ago, # ^ |   0 1 ab a
•  » » » » 17 months ago, # ^ |   0 Can you told me why I am getting TLE on test 30 in Problem D? -_- I used binary search. Can it be a reason? Here is my solution :https://codeforces.com/contest/1553/submission/126554472
•  » » » » » 17 months ago, # ^ | ← Rev. 2 →   0 na apu,,,,,..... nlogn is efficient......... but you declare vector odd[200010] which complexity is O(n),n=size......... total complexity will be O(n*q)......... then if q=100000, it will definitely fail..............https://codeforces.com/contest/1553/submission/126596025
•  » » » » » » 17 months ago, # ^ |   0 can we use bitmask enumeration technique to generate all possibilities in problem C?
 » 18 months ago, # |   +73 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.
•  » » 18 months ago, # ^ |   +39 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.
•  » » » 18 months ago, # ^ |   +5 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
•  » » » » 18 months ago, # ^ | ← Rev. 2 →   +55 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...... QwQJust sharing some thoughts...... QwQIf 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 — CodeforcesThank you very much for your time reading this! I really appreciate it.
•  » » » » » 18 months ago, # ^ |   +21 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
•  » » » » » » 18 months ago, # ^ |   +19 Shouldn't the complexity be $O(\sqrt[\lambda]{M} + M)$?
•  » » » » » » » 18 months ago, # ^ |   0 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.
•  » » » » » » » » 18 months ago, # ^ |   +8 $\lambda = \log n$ requires $O(\log n)$ for both updates and queries.
 » 18 months ago, # |   +8 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?
•  » » 18 months ago, # ^ |   +15 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.
•  » » » 18 months ago, # ^ |   +8 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.
•  » » 18 months ago, # ^ |   +8 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.
 » 18 months ago, # |   -10 Auto comment: topic has been updated by Harbour.Space (previous revision, new revision, compare).
 » 18 months ago, # |   +23 F in chat for person who lost scholarship due to hacks
 » 18 months ago, # | ← Rev. 2 →   +17 I used a sledgehammer to crack a nut. Used KMP algorithm in B.My submission: 123364212Works in $\mathcal O(n^2)$ probably.
•  » » 18 months ago, # ^ |   0 Could U give a brief solution on your idea?
•  » » » 18 months ago, # ^ | ← Rev. 2 →   +1 In short, I'm searching for all prefixes of $t$ and reverse of the remaining part in $s$. SpoilerAt every $i$-th step, maintain $i$-th prefix of $t$ and the reverse of the remaining part of $t$. Formally, maintain $p_i = t_0t_1\cdots t_{i-1}$ and $q_i = t_{n-1}t_{n-2}\cdots t_i$. What we look for is an $i$, such that $p_i$ and $q_i$ are substrings of $s$ and if $p_i$ ends at position $k$ in $s$, then $q_i$ should end at $k-1$. Also, the corner cases are if $q_0$ or $p_n$ is present in $s$.Use KMP algorithm to search for corner cases. For the interior cases, I've stored all (ending) indices at which they're found (again using KMP algorithm) and used two pointers to match the condition for $k$. If any $i$ satisfies, or any corner case is satisfied, I'm done.The KMP algorithm works in $\mathcal O(n)$ time and there are $\mathcal O(n)$ searches done.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.
»
18 months ago, # |
+94

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
 » 18 months ago, # |   +3 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.
•  » » 18 months ago, # ^ | ← Rev. 2 →   +1 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.
•  » » 18 months ago, # ^ | ← Rev. 2 →   0 here : 123296482 some explanationSubstr is a fuction I copied from gfg, which checks if one string is substring of another. Other than that the solution is self explanatory.
•  » » 18 months ago, # ^ |   +1 solution i think my dp solution is n2 .correct me if i am wrong.
•  » » » 18 months ago, # ^ |   +1 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.
 » 18 months ago, # |   +47 TerriblePretestsForces
 » 18 months ago, # | ← Rev. 2 →   +5 Preparation : will not be revealed for now cuz we care for their safety ...lol .. Btw fstforces
 » 18 months ago, # |   0 Wow, problem B was really harder than many people thought.
•  » » 18 months ago, # ^ |   +13 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.
•  » » » 18 months ago, # ^ | ← Rev. 4 →   -15 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
•  » » » » 18 months ago, # ^ |   +6 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
•  » » » » 18 months ago, # ^ | ← Rev. 2 →   0 it's not strict n^3 it's lesser than n^3 / 2 and even n^3 alone runs easily under a second
•  » » » » 18 months ago, # ^ |   +1 I think it's $O(N^3)$ because $std::string.find$ is quadratic in worst case
•  » » » 18 months ago, # ^ |   0 Ya, same happened with me!
 » 18 months ago, # |   0 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 :)
 » 18 months ago, # |   +46 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.
 » 18 months ago, # |   0 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
 » 18 months ago, # |   0 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??
 » 18 months ago, # |   0 Where is the D?
•  » » 18 months ago, # ^ |   0 read um_nik's code and dry run on a few cases u will understand.
 » 18 months ago, # |   0 used brute O(n^3) solution in B. Accepted in PyPy in only 358ms123296399
 » 18 months ago, # |   0 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?
•  » » 18 months ago, # ^ |   0 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.
 » 18 months ago, # |   +86 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.
 » 18 months ago, # |   -23 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.
 » 18 months ago, # |   0 Why can not I see the tutorial of the problem D
•  » » 18 months ago, # ^ |   0 Because tutorial of D is not available.
•  » » » 18 months ago, # ^ |   0 Thanks
•  » » 18 months ago, # ^ | ← Rev. 6 →   +1 Solution for D$Problem:$ 1553D - BackspaceWe iterate from right to left, or from back to front.Let $n$ be the current size of $s$ and let $m$ be the current size of $t$.Now, if $s[n] == t[m]$ Then we simplify the question to $s := s[1...n - 1]$ and $t := t[1...m - 1]$. Thus, we reduce the size of $s$ and $t$ once.The other case is when $s[n]$ != $t[m]$, Here we obviously need to click a backspace otherwise our last character will be $s[n]$ which is not what we want. So, we click a backspace. But when we do so, we delete some previous character(if any) as well. Therefore, we reduce the problem to, $s := s[1... n - 2]$ and $t$ remains the same. Thus, you pop $s$ twice.After one of the strings is empty you stop and break your loop.For your final answer, if string $t$ is empty the answer is "YES" else, "NO".Time Complexity: $O(n + m)$.My Code: 123381503The 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.
•  » » » 18 months ago, # ^ |   0 thanks
•  » » » 18 months ago, # ^ | ← Rev. 2 →   0 why we have to move right to left ,i tried an approach where i am are moving from left to right and if difference between some part is even we can delete itbut it is giving wrong answer my codecan you please tell which case i am missing?or can you tell me how i can think of approach of moving pointer from right to left?
•  » » » » 18 months ago, # ^ |   0 You can just reverse strings right after reading them from the input and then do left to right processing in the rest of your code. That's what I did myself during the contest. If the standard C++ library doesn't offer a native way to reverse strings, then it makes sense to have such function somewhere in your collection of code templates.The main idea is that in many cases it is possible to do some cheap pre-processing of the input data to make the problem easier. Sometimes it's sorting of the input data, sometimes it's reversing the order of elements, etc.
•  » » 18 months ago, # ^ |   0 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.
 » 18 months ago, # | ← Rev. 4 →   +8 I wake up and see result problem D Time limit on test 99 , very sad!!!!!!
 » 18 months ago, # |   0 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
•  » » 18 months ago, # ^ |   0 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.
•  » » » 18 months ago, # ^ |   0 I am asking about problem C. Can you help me why is the answer 9 in last test case of problem
•  » » » » 18 months ago, # ^ | ← Rev. 5 →   0 ExplainationOkay, so the given string is - 0100000000The game isn't decided till the second last shot because the referee thinks that this string is possible- 0100000010In the above string the score is [1 : 1].But after the 9th shot the referee knows the score is [0 : 1] and its second teams turn, and irrespective of whether or not the last shot goes in or not the second team is bound to win.But until the 9th shot the end result was unknown, it could result in a tie or the second team might win.Therefore the minimum possible shots required to determine the absolute end result is 9.I hope you understood. Incase something wasn't clear, feel free to ask me.
 » 18 months ago, # |   -24 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)
 » 18 months ago, # |   +1 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"; } 
 » 18 months ago, # |   +6 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. :)
•  » » 18 months ago, # ^ |   0 i noticed that too.haha i wonder if they will be in danger if their handles are shown?
 » 18 months ago, # | ← Rev. 2 →   0 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?
 » 18 months ago, # |   0 I tried solving B using two pointers, getting WA on TC 14. Can anyone point out what's wrong? 123384175
 » 18 months ago, # | ← Rev. 3 →   0 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.
•  » » 18 months ago, # ^ |   0 my solution was even simpler but had almost the same idea 123325031
•  » » » 18 months ago, # ^ |   0 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.
 » 18 months ago, # | ← Rev. 3 →   0 Oops, sorry about that!! Thanks to Nezzar and Rossoneri_Forever!!
•  » » 18 months ago, # ^ |   0 Your output is lowercase, I think the checker converted it to uppercase.
 » 18 months ago, # | ← Rev. 5 →   -11 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" ; } 
 » 18 months ago, # |   0 Great contest from which I learned a lot
 » 18 months ago, # |   0 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.FirstIf you know of more such Problems, it would be nice if you could comment them down here.
 » 18 months ago, # |   0 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)$
 » 18 months ago, # | ← Rev. 2 →   +17 Deleted. 1001 way to overcomplicate your solution, lol.
•  » » 18 months ago, # ^ |   +8 Lol.I did the same thing. I initially did 200 times and got an unnecessary TLE because that.
 » 18 months ago, # |   0 Auto comment: topic has been updated by Harbour.Space (previous revision, new revision, compare).
 » 18 months ago, # |   0 "Preparation: Will not be revealed for now because we care for his/their safety."
 » 18 months ago, # |   0 Can someone provide tutorial for Um_nik solution of problem D. It would be really helpful.Thanks in advanced :)
•  » » 18 months ago, # ^ | ← Rev. 3 →   0 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.
 » 18 months ago, # |   0 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??
•  » » 18 months ago, # ^ |   +8 If the sum of many numbers is n, only three of them can be greater than n/3.
•  » » » 18 months ago, # ^ |   0 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?
•  » » » » 18 months ago, # ^ |   0 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.
•  » » » » » 18 months ago, # ^ |   +8 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.
•  » » » » » » 18 months ago, # ^ |   +8 It will benefit you. Upsolving is much more important than solving problems during the contest.
 » 18 months ago, # |   +5 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.
 » 18 months ago, # |   +8 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
 » 18 months ago, # |   0 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.
 » 18 months ago, # |   +11 the solution of Problem F may be wrong because it won't print any integer on test 26. Please check your standard solution, thanks.
 » 18 months ago, # |   +6 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.
•  » » 18 months ago, # ^ |   0 me too
 » 18 months ago, # |   0 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
 » 18 months ago, # |   +40 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.
 » 18 months ago, # |   -10 In problem E I think you mean the sum of cnt[k]= n, not n! This is why mathematicians shouldn't get overly excited (:
 » 17 months ago, # |   0 Can we use submask enumeration technique to generate all possibilities for problem C?
 » 16 months ago, # |   +8 Will preparation for B and D ever be revealed?
 » 4 months ago, # |   0 I tried using DP, but my solution gives the wrong answer. Can someone please tell me what I did wrong #include #define ios \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define int long long #define YY cout<<"YES"<>mem; bool solve(string &s,string &t); bool solver(string &s,string &t,int i,int j); signed main(){ ios; int q; cin>>q; while(q--){ string s,t; cin>>s>>t; bool ans=solve(s,t); (ans)?YY:NN; } return 0; } bool solve(string &s,string &t){ mem=vector>(s.size(),vector(t.size(),-1)); for(int i=0;i