### dario2994's blog

By dario2994, 4 years ago,

Broadly speaking, problems A-B-C-D were "div2 problems", while F-G-H were "strong grandmaster problems" (with E staying in the middle). I did not expect anyone to solve all the problems and thus I decided to give the scoring F+G=H (so that maybe someone would have solved H).

Many of the problems (A, C, D, E, G) admit multiple solutions. Sometimes the core of the solution is the same (C, D) and sometimes the solutions are truly different (A, E, G).

If you are an experienced participant, I would like to hear your opinion on the problems. Feel free to comment on this post or send me a private message.

Overview of the problemset

A

B

C

D

E

F

G

H

#### Solutions

A

Solution code
B

C

D

E

F

G

H
• +758

| Write comment?
 » 4 years ago, # |   +55 Awesome editorial and even awesome questions. After this round, I feel like practicing more now.
 » 4 years ago, # |   +82 I really liked this contest. All problems between A and E are well-balanced. They are not almost ad-hoc, and they are not stupid realization. Ideal balance! Thanks for this round!
•  » » 4 years ago, # ^ |   +106 But i must to say, that in my opinion it is makes no sense to do score distribution like 500-750-1000-1000-1500
 » 4 years ago, # |   -9 thanks for blazing fast editorial. Loved the problems <3
•  » » 4 years ago, # ^ |   -9 How did you love the problems while you haven't even submitted any?
•  » » » 4 years ago, # ^ |   -11 lol get downvoted xD.
 » 4 years ago, # | ← Rev. 2 →   +15 For problem C This is a classical dynamic-programming task with a twist. Which task does this refer to?
•  » » 4 years ago, # ^ | ← Rev. 2 →   +10 It's quite similar to the longest increasing subsequence, but the condition to pick the previous element is $dist(i, j) \leq t_j - t_i$ instead of $a_j > a_i$.
•  » » » 4 years ago, # ^ |   0 There is the use of upper_bound in the regular longest increasing subsequence problem of O(nlog(n)). But in this problem how I make a binary search. (dist(i,j)≤tj−ti) can give only true or false, not greater than or less than. Actually, I can't be sure my temp array will be sorted.
•  » » » » 4 years ago, # ^ |   +6 The "twist" is not binary search: it's that $t_j - t_i \geq j - i$ and $dist(i, j) \leq 2r$, hence the condition is true for each $i, j$ such that $j - i \geq 2r$.
•  » » » » » 4 years ago, # ^ |   0 Oh, thanks. Got it :)
•  » » » » » » 4 years ago, # ^ |   0 TheScrasse PrantaSaha Can someone please explain what 2*r means? The idea is that if |k−i| is big, then i and k are always compatible. More precisely, if k−i ≥ 2r then tk−ti ≥ 2r How can we be so sure about this?
•  » » » » » » » 4 years ago, # ^ |   0 Since the side of the grid is $r$, the distance of the farthest vertices (two opposite corners) is $2r - 2$.
•  » » » » 3 years ago, # ^ |   +4 After reading your comment a was able to understand editorial Thanks
•  » » 4 years ago, # ^ |   0 I think the task is Longest increasing subsequence:- https://www.geeksforgeeks.org/longest-increasing-subsequence-dp-3/
 » 4 years ago, # |   +60 it fits easily in the time-limit. it doesn't...
•  » » 4 years ago, # ^ | ← Rev. 2 →   +34 I have quickly checked your last submission during the contest, it seems to me that it is $O(n^4)$ (you are calling janusz.dinic() $O(n)$ times). If I am wrong (which is very likely), sorry.If you implemented the first solution in the editorial in $O(n^3)$ and you got time-limit-exceeded, I am sorry, that was of course not intended.Since I am here, let me comment a bit more on the time-limit of problem G. I have the feeling that in many flow problems, the general mentality is "let's ignore complexity because any flow implementation will work". In this problem this was not true. A nontrivial amount of contestants got TLE because of this. Before the contest I thought a lot about this time-limit, because I knew it would have generated quite a bit of struggling. The fundamental reason why I decided to keep it as it is, was to avoid $O(n^4)$ solutions passing and to award contestants that instead of using fancy (but with bad complexity/terrible constants) implementations of the flow algorithm were implementing the good old Ford-Fulkerson (proving its complexity!). It might be that this choice generated more suffering than joy... but as always it is much easier to judge a posteriori.
•  » » » 4 years ago, # ^ | ← Rev. 2 →   +25 I run dinic() $n$ times, but in total, I'll push only $O(n)$ units of flow (I'm using the network from the previous iteration).After the contest, I've changed Dinic to work like Ford-Fulkerson, so it doesn't run bfs. It was a bit faster, which was enough.
•  » » » » 4 years ago, # ^ |   +35 That is unfortunate and it is my fault. Hopefully next time I will not make the same mistake.
 » 4 years ago, # |   +15 Anyone wasted an hour in B?
•  » » 4 years ago, # ^ |   +2 I was stuck on B for the entire contest after solving A in 00:04 :'(
•  » » 4 years ago, # ^ |   +3 I solved A in 00:14 and B in 02:10. That was a hard time.
•  » » 4 years ago, # ^ |   +8 I solved B at 2:59 .
•  » » 4 years ago, # ^ |   +4 I couldn't solve B. I got the idea right but I couldn't prove it. Feeling lame especially when you are(were) an expert.
 » 4 years ago, # |   -179 In parallel universe.
 » 4 years ago, # | ← Rev. 2 →   +26 If $a=b+1$ and $b$ is even, then $a^b=1$.In Hint $4$ of the first solution of problem $E$, maybe it should be $a\oplus b=1$($\oplus$ denotes xor)...Also in Hint $3$ of the second solution, it should be $2^{19}$ but not $2^19$.
•  » » 4 years ago, # ^ |   +16 Thank you, fixed.
 » 4 years ago, # | ← Rev. 4 →   +2 Many of them could have got ac on D if it were 2*n steps,lol. By the way,thanks for a great contest.Liked it. Thanks for strong pretests
 » 4 years ago, # |   +4 Me :Could only solve one, feeling low...Also Me : After reading the overview of problemset...I am glad I solved A.
 » 4 years ago, # |   +59 This is peak editorial writing. From giving some extra time to the ones who were really close to getting AC on H to writing multiple hints for us to be able to figure out the rest of the solution by ourselves. Great work dude!
•  » » 4 years ago, # ^ | ← Rev. 2 →   +11 I love that, I was close to getting C and only read the hints and was able to solve it. A good way to learn is by using hints instead of revealing the whole solution.
 » 4 years ago, # |   +3 Thanks for the awesome Tutorial keep it with hints its such a good way of learning and explanation :D !
 » 4 years ago, # |   +7 The way of presentation of the Editorial is very Nice. Going through the Hints before The Actual Solution really helps in learning. I request all editorial should be posted like this (Hints and Then solution).
 » 4 years ago, # |   -11 I have lost more than 200 rating points in the last 3 contests, Don't really know what's happening :/
•  » » 4 years ago, # ^ |   +6 You just reached where you actually belonged :P
•  » » » 4 years ago, # ^ |   +3 hahaha, Not sure about you. But I don't belong here. Its time to increase my rating now I think
•  » » » » 10 months ago, # ^ |   +3 how it is going?
 » 4 years ago, # |   +7 Great format for the editorial! Loved the bunch of hints before the elaborated solution. Thank you!
 » 4 years ago, # |   +10 it would have been better , if the editorials were given with the problems in the contest.
 » 4 years ago, # |   +48 Here are video solutions for A-E, as well as complaining about gaining rating (apparently)
 » 4 years ago, # |   -10 sorry for such a silly question but why am i getting TLE here? 95114705 I tried to form all possible permutations coz the constraints were very small. But still i got TLE. If anyone got time a slight help would be great. Thank you. Have a good day
•  » » 4 years ago, # ^ |   +3 what is the value of 50! ?(50 factorial).
 » 4 years ago, # | ← Rev. 2 →   -29 Can anyone tell why my solution is incorrect for Problem — B ( Chess Cheater )? My approach : Step 0: Find the initial score and store it in variable sum Step 1: Find all contiguous Loss substrings and store (length,0) if the substring is not a prefix/suffix (length,1) if it is a suffix/prefix Step 2: Sort the vector in increasing order, putting prefix and suffix substrings at the end Step 3: iterate for elements in the sorted vector ( for i=0;i < it.size(); i++ ) if( k >= it[i]) // meaning we can change the whole interval sum += 2*it[i] +1 if the i'th substring of L's is not a suffix or prefix sum += 2* it[i] if i'th substring of L's is a prefix/suffix k -= it[i] else if( k < it[i] ) // this is the last substring we can change, and we can't change it fully sum += 2*k k=0; Step 5: cout<< sum <<" \n" Link to submission : Can anyone point out the mistake kindly? Thanks in advance :)
•  » » 4 years ago, # ^ | ← Rev. 2 →   0 I had the same solution in contest. Consider the case 2 0WW
•  » » 4 years ago, # ^ |   0 Step 2: Sort, ..., putting prefix and suffix substrings at the end However, this isn't what happens in the code — you sort by length first, then consider the type.
•  » » » 4 years ago, # ^ |   0 Yeah, I just figured it out after posting the comment :'3 Thanks for the prompt reply anyway. I guess sometimes we rookies just lost, tearing out hair over trivial mistakes which then builds frustration and tosses the self confidence into a black hole temporarily!
•  » » » » 4 years ago, # ^ |   0 Or just have poor debugging skills...
 » 4 years ago, # |   +3 C was much harder than D for me.
•  » » 4 years ago, # ^ |   0 Depends. If someone has good DP knowledge, C was way more easier than D and less time consuming. I took like one hour and half in D which I was too late to solve in contest so I solved it and AC after contest.
 » 4 years ago, # |   +6 Nice editorial! It would be great if we can have hint on all the future editorials! (but that would be time consuming for the writer)
•  » » 4 years ago, # ^ |   +33 I am glad that the hints were so appreciated. I have just followed a suggestion by Errichto.In any case, writing hints requires way less effort and time than writing the editorial. So, I would advise any problemsetter who has some spare time before the contest (or also during the contest!) to write hints.
 » 4 years ago, # |   +1 Great Set of questions. Even the editorial in this format is very informative and help in logic building.
 » 4 years ago, # |   +3 This is the toughest round for me so far.
•  » » 4 years ago, # ^ |   0 Same, couldn't solve C or D ..
•  » » » 4 years ago, # ^ | ← Rev. 2 →   0 Found solutions to D and E but couldn't code it, and failed B due to a very stupid bug.
•  » » » » 4 years ago, # ^ |   0 Solved C at Last moment just one step missed. Chain will continue.
•  » » » » » 7 months ago, # ^ |   0 I am learning and then forgetting what I learnt !! and sometimes I think I do not learn anything from problem.sometimes I even feel there is no such thing as learning in CP bcoz every time a new problem will come up.I dont know when I will see the twists of problem. I am not sure whats the point of even solving problems bcoz those problems wont repeat themselves and you can't apply it to other problems. For Instance Take Problem C.It is already closer to standard problem or problem which I solved but could'nt move an inch towards solution
 » 4 years ago, # | ← Rev. 2 →   +104 There is an elementary solution to E which does not use Bezout's Theorem. First idea of the solutionLet ^ denote the XOR operation. We can assume that the bit that is worth $2$ is off in $x$, because if we get an $x$ such that the bit that is worth $2$ is on, we can take $x' = (x$ ^ $2x)$ (this will be crucial later). The claim is that we can find a multiple of $x$, such that its last $\lceil\log_2(x)\rceil$ digits are zero, except for the last one, which is a $1$. First step of the solutionWe do this by saving all $x\cdot 2^k$ for $1 \leq k \leq \lceil\log_2(x)\rceil$ which we can do in $\lceil\log_2(x)\rceil$ steps, then constructing a number $q$ by first taking $x$, then going from $i = 1$ to $\lceil\log_2(x)\rceil$, and if $q$ has the bit that is worth $2^i$, then we xor $p$ with $x\cdot 2^i$, which has that bit as one, and all smaller bits as zero. Now $p$ is some prefix, then $\lceil\log_2(x)\rceil$ zeroes, then a $1$ in binary. Completing the solutionThe next claim is that $(p + x)$ ^ $(p$ ^ $x) = 2$. This is true, because the first bits are the same it both numbers, so we need to only care about the last $\lceil\log_2(x)\rceil$ bits. For $p$ ^ $x$ this is $x - 1$, for $p + x$ this is $x + 1$, and because the bit that is worth $2$ is off in $x$, the XOR of these two numbers is $2$. Now, having $2$, we construct $2^i$ for $i = 1$ to $\lceil\log_2(x)\rceil$, and then we can just turn the bits that are not worth 1 in $x$ off by XORing with the suitable power of 2.
 » 4 years ago, # |   -52 For B, I used the idea of finding the contiguous substring with maximum consecutive Ws by performing at most k flips(where a flip is from W to L, L to W). Then I would calculate the winning score. I am getting the wrong answer on pretest2. Can somebody help me find out what's wrong with my solution?Here is my code — void solve() { cin >> n >> k; string s; cin >> s; vi A(n); fo(i,n){ if(s[i]=='W') A[i] = 1; else if(s[i]=='L') A[i] = 0; } // Now I find the contiguous substring with maximum consecutive 1s by doing at most k flips. int l=0, r=0, maxLen=INT_MIN, maxL, maxR, c=k; for(r=0,l=0; r=0) break; if(A[l]==0) c++; l++; } } else{ if(A[r]==0){ c--; if(c<0){ r--; continue; } } if((r-l+1)>maxLen){ maxLen=r-l+1; maxL=l; maxR=r; } } } int ans = 0, j = maxL; if(maxLen!=INT_MIN){ while(j<=maxR){ A[j] = 1; j++; } fo(i,n){ if(i==0){ if(A[i]==1) ans++; } else if(i>0 && A[i]==1){ if(A[i-1]==1) ans+=2; else ans++; } } } cout << ans << endl;}
•  » » 4 years ago, # ^ |   0 Note that the solution might not be to create a single substring: consider the input 1 9 2 WLWLLLWLW 
 » 4 years ago, # |   +96 hence I will leave them a couple more hours to try getting AC https://codeforces.com/contest/1427/submission/95152627It turns out my problem was that I was simply losing too much precision when considering escaping through a very close point :( Knowing that my answer is actually bigger than the correct one was enough to find the issue immediately.Thanks for the contest!
•  » » 4 years ago, # ^ |   +19 Congratulations!By the way, I had exactly the same bug when preparing the problem. I lost a full day on that!
•  » » 4 years ago, # ^ |   0 Can you very briefly describe the solution? I'm dying to know how far away I was.I assumed that it's enough to consider the prisoner to start from some point on the boundary and guards can then choose where they start. Iterate over segment of prisoner, ternary search his exact position there, one guard must stand at same position, iterate over segment of the other guard, ternary search his exact position, then check with Apollonius circles who wins (well, actually find the ratio for tie).
•  » » » 4 years ago, # ^ |   +19 I have posted the editorial.
•  » » » 4 years ago, # ^ | ← Rev. 3 →   +20 It's very similar to the editorial, but in a few words:indeed, let's assume that the prisoner starts at the boundary. Then one of the guards must be in the same point or they'll escape immediately, so the other guard can guard only one of two segments that this point splits the boundary into. So if we compute the speed needed to catch the prisoner that runs to some point at the bottom part (via iterating over the segment we run to and using ternary search), the speed needed to catch the prisoner that runs to some point at the top part, and take the minimum of those two values, it will be a lower bound on the answer. Now we treat it as a blackbox function f(x) and try to find its maximum (I'm not sure ternary search within each segment is enough, so I had something slightly more general). I don't have a proof that the maximum of those lower bounds is the answer, I guess the editorial does :)
 » 4 years ago, # |   +3 In the question C... I tried a code with dp approach but with some restriction (difference of index). It passed all the test cases.But for this test case my code outputs 0 but the answer should be 1. 500 2100 50 602100 500 500Are the test cases of C weak or Am I wrong somewhere?Submission link:- https://codeforces.com/contest/1427/submission/95152766
 » 4 years ago, # |   +8 In problem C, I thought that R in the input is useless then tried solving the inequality tj — ti >= |xj — xi| + |yj — yi|, (tj > ti) to solve the problem in n*log(n) time but didn't come up with the solution, is there any such faster solution possible?
 » 4 years ago, # |   +26 My solution for problem G seems to be a weird modification of the standard solution.I do binary search on the candidate values, run min-cut, then divide the vertices into two halves. Thus there will be $O(\log n)$ layers, each consisting a total of $O(n^2)$ vertices and edges. The complexity will be $O(n^3\log n)$. (Since Dinic's algorithm works in $O(E\min\{E^{1/2},V^{2/3}\})$ on networks with unit capacities)
 » 4 years ago, # |   +1 Difficulty of 'B' should not be less than 1500
 » 4 years ago, # | ← Rev. 2 →   +45 Another deterministic solution of E:Step 1: Let $p \in N$ be the unique number such that $2^{p-1} < x < 2^{p}$. Write $2^p x$ and $(2^p - 1) x$ on board with $O(p)$ operations.Step 2: Write $(2^p x) \oplus ((2^p - 1) x) = 2^{p+1} - x$ on the board. Then, write $x+ (2^{p+1} - x) = 2^{p+1}$ on the board.Step 3: We can write $2^i$ for all $i \ge p+1$ on the board. Write $2^p$ by using xor operations for all the bits of $2^p x$ except $2^p$.Step 4: Write $(2^{p+1} - x) \oplus (2^p) = (2^p - x)$ and repeat the steps with new $x = (2^p - x)$ while $x \ge 1$. New $p$ of new $x$ is strictly smaller than current $p$, so it repeats at most 20 times.
 » 4 years ago, # | ← Rev. 2 →   0 Can dynamic programming in Problem C be done with recursion and memoization? If yes, how? Please help.
•  » » 4 years ago, # ^ |   +1 Yes, taking help from the "alternative optimization" in the editorial, you can solve it using recursive DP, just make sure you don't consider more than $4*r$ of the next celebrities.That being said, the iterative approach is cleaner and easier, so try to practice that instead.
•  » » » 4 years ago, # ^ |   0 Alright! I'll try both. Thank you! :)
•  » » » 4 years ago, # ^ | ← Rev. 2 →   0 My O(n * r) iterative Java solution is getting a TLE (I haven't used the alternate optimization, but that's shouldn't be necessary right?)https://codeforces.com/contest/1427/submission/95385701I saw solutions in C++ do the exact same thing and get an AC :-(
 » 4 years ago, # | ← Rev. 2 →   +22 Problem D is actually very easy if you realize the operation is same as reversing each deck individually and reversing the entire array. Since you can fix the reversing of the entire array with one operation, the problem is reduced to "sort an array with at most N subarray reverses", which is easy
•  » » 4 years ago, # ^ |   +8 Good one!
•  » » 4 years ago, # ^ |   0 I would be thankful if you can give a quick example.
•  » » » 4 years ago, # ^ |   +3 Let's say array is $[1, 3, 4, 2]$ and you choose decks $D_1 = [1, 3]$ and $D_2 = [4, 2]$. Then, after the operation it becomes $[4, 2, 1, 3]$. This is the same as these two operations applied, one after another: Reverse the decks: $[1, 3, 4, 2]$ -> $[3, 1, 2, 4]$ (here each deck was reversed individually inside the array). Reverse the array: $[3, 1, 2, 4]$ -> $[4, 2, 1, 3]$ Ignoring the second operation, according to the link I posted to the solution of the reduced problem, you would choose decks with sizes: $[1, 3]$ (puts 2 in its place) and array becomes $[1, 2, 4, 3]$ $[1, 1, 2]$ (puts 3 in its place) and array becomes $[1, 2, 3, 4]$ Now, to consider the second operation, you just need to keep a flag if the array is reversed or not. If it is, you reverse the decks you print. If by the end this flag is true, you print one last time: $[1, 1, 1, 1]$ (this will only reverse the array). Hope it is clear now!
 » 4 years ago, # | ← Rev. 3 →   +128 In the editorial for problem A, it's conjectured that a random shuffle works with probability at least $\tfrac1n$ (assuming the sum of all the numbers is nonzero). This is true, and here is a proof. The key claim is that, given any shuffle, some cyclic permutation of it works. This easily implies the desired result.Suppose that the claim is false for some shuffle $a_1,\ \dots,\ a_n$ (so $a_1 + \dots + a_n \ne 0$). Interpret all indices modulo $n$. Since no cyclic permutation of this is valid, for any $k$, there exists some $f(k)$ such that $a_k + a_{k+1} + \dots + a_{f(k)-1} = 0$.Thus, we have a function $f$ on the integers modulo $n$. (Formally, we have $f\colon \mathbb Z/n\mathbb Z \to \mathbb Z/n\mathbb Z$.) Thus, this function has a cycle, say $t_1 \to t_2 \to \dots \to t_k \to t_1$.This gives us the $k$ relations $a_{t_1} + \dots + a_{t_2-1} = 0$, $a_{t_2} + \dots + a_{t_3-1} = 0$, $\dots$, $a_{t_k} + \dots + a_{t_1-1} = 0$. Summing these all up, we get $c(a_1 + \dots + a_n) = 0$, where $c$ is the number of "revolutions." Thus $a_1 + \dots + a_n = 0$, as wanted.
•  » » 4 years ago, # ^ | ← Rev. 2 →   0 Very cool! If you don't mind, I will add a link to your comment in the editorial.UPD: Added.
•  » » » 4 years ago, # ^ |   0 That’s okay with me. Thanks for the great contest!
•  » » 4 years ago, # ^ |   0 Thus, we have a function f on the integers modulo n. (Formally, we have f:Z/nZ→Z/nZ.) Thus, this function has a cycle, say t1→t2→⋯→tk→t1 I didn't get this. Will you please elaborate on it?
•  » » » 4 years ago, # ^ |   0 Recall that for each $k$, we have an $f(k)$ for which $a_k + a_{k+1} + \dots + a_{f(k)-1} = 0$.Now draw an arrow from $a_k$ to $a_{f(k)}$ for each $k$. Since we have one arrow leading out of each term, there must exist a cycle of arrows. (To see this, imagine following the arrows: travel from $a_k$ to $a_{f(k)}$ to $a_{f(f(k))}$, etc. Then eventually we must revisit some term, which gives a cycle.)Suppose the cycle takes $a_{t_1}$ to $a_{t_2}$ to $a_{t_3}$ to ... to $a_{t_k}$ to $a_{t_1}$. Now we can follow the last paragraph of the proof.
•  » » 4 years ago, # ^ | ← Rev. 2 →   0 That's pretty good! I think the below also works as proof (correct me if I'm wrong).In the case where n-1 numbers are 0 and one is non-zero, the only possible permutation that gives you an acceptable answer is when non-zero number comes first. Probability of that happening is 1/n. Probability will keep decreasing as you replace non-zero numbers with 0, so the lowest positive probability is 1/n.
 » 4 years ago, # | ← Rev. 2 →   0 I have a straight forward solution for E with no randomization or coprime numbers required.Let k be the MSB of x. Notice that we can get 2^n * x for all n by adding x to itself and then repeating. Now, for any number on the board y, we can set all bits >= k equal to 1. We can do this by xor-ing 2^n*x to set each bit above k if it is not set for some appropriate n. So we just need to find two numbers for which, after setting all bits >= k to 1, all of the bits below k are the same, except the 1 bit. We can just check the first 3e6 multiples of x (no randomization required).
 » 4 years ago, # |   0 I solved problem C the way you suggested and thought that 2rn = 10^8 will not fit so I didn't implement it...Did this happen to anyone else?
•  » » 4 years ago, # ^ |   -7 Sadly same thing happened with me, I was trying to think of applying segment tree on n but it got too messy. Hopefully I would have tried D first which was relative easier to me.
•  » » 4 years ago, # ^ |   0 I implemented as said in the tutorial. Hope it helps :) Solution
•  » » 4 years ago, # ^ |   0 Same. Was able to think O(nr) and was like 10^8? No that won't work.
 » 4 years ago, # |   +1 95127605 I used random_shuffle for problem A because the constraints were small whereas everybody else used sorting. Is it my luck that my submission got accepted? Also, what are the chances that my solution won't work?
 » 4 years ago, # | ← Rev. 2 →   0 For E, I had similar solution to the gcd one, but the step of finding a co-prime pair is randomized. It randomly generates new numbers until it finds a co-prime pair. It too completes in $\le 100$ operations. 95149535
 » 4 years ago, # |   +8 one of the best editorial. Loved it!!
 » 4 years ago, # |   +10 if it is possible, try to keep hints option in every editorial .. it is so beneficially for a newbie like me :)
 » 4 years ago, # |   0 I like the solution to E with bezout theorem very much! Thanks for fast editorial.
 » 4 years ago, # | ← Rev. 3 →   +1 Could you check pls what is wrong with my solution for C (WA15) codecin >> k >> n; vector> v(1e6+1, {-1,-1}); v[0] = {1,1}; for(ll i = 0; i < n; ++i) { cin >> t >> p >> q; v[t] = {p,q}; m = t; } vector dp(m+1, 0); sum = 0; for(ll i = 0; i < m+1; ++i) { if(v[i].first == -1) continue; if(i-k*2 > 0) { sum = max(sum,dp[i-k*2-1]); dp[i] = max(dp[i], sum+1); } for(ll j = i+1; j < min(i+k*2+1, m+1); ++j) { if(v[j].first == -1) continue; if(j-i >= abs(v[j].first-v[i].first)+abs(v[j].second-v[i].second)) { if(dp[i] || !i) dp[j] = max(dp[j], dp[i]+1); } } } mx = 0; for(ll i = 0; i < m+1; ++i) { mx = max(dp[i], mx); } cout << mx;
 » 4 years ago, # |   0 Why is the approach at problem A correct???
 » 4 years ago, # |   +3 I stupidly misread the constraints for D, and even more stupidly called my results vector in the solution "omgconstraints", as a way to punish myself for not reading constraints, by typing that name like 50 times. Given that my successful submission for D was 10 seconds before the contest ended, I cursed myself every time i typed "omgconstraints" rather than the usual "res" that I use. Had I known that these extra letters might have pushed cost me the problem, I would have definitely thought twice.
 » 4 years ago, # | ← Rev. 2 →   0 Hey, I have some problems with B. Just Have a look at this test case and tell me how's the answer for this test case is 16.112 2WWLWLLWLWWWLAns:- 16 I think the answer should be 15
•  » » 4 years ago, # ^ |   0 WWWWLLWWWWWL
•  » » » 4 years ago, # ^ |   0 Thank-you bro.
 » 4 years ago, # |   0 In problem C.Who can explain completely Hint 3 ?
•  » » 4 years ago, # ^ |   +1 I have already understood it!
 » 4 years ago, # |   +71 Based on this contest, I believe that dario2994 is one of the best problemsetters on CF. Would love to see another contest from you!
 » 4 years ago, # | ← Rev. 2 →   0 Can someone explain step1 of the deterministic solution of Problem E . Particularly this line :- y=(2ex)^x=(2e+1)x−2e+1 and therefore gcd(x,y)=gcd(x,2e+1)=1
 » 4 years ago, # |   +10 Who is an "experienced participant" in your view dario2994?
•  » » 4 years ago, # ^ |   +46 Anyone who participated in at least 10 contests and is able to enjoy a contest even if he gets a negative rating change.
•  » » » 4 years ago, # ^ | ← Rev. 3 →   -6 .
•  » » » 7 months ago, # ^ |   0 Let me rewrite the statement.Anyone who participated in at least 10 contests and is trying to improve even he doesn't improve
 » 4 years ago, # | ← Rev. 2 →   +12 Hi, Can anyone help to understand why my solution of problem D works. Here is the link to solution : SOLUTIONApproach: I am counting the number of operations from 0.When the parity of number of operation is even : In this case I select subarrays staring from first element till the elements are in decreasing order. When I find an element that is bigger than previous element, I stop and considers the chosen elements as a split. Now I start fresh from this element and repeat this process until I have some k splits. Now I perform the operation on them.When the parity of operation is odd, I am doing the same process except I chose subarrays that are strictly increasing.For example : Input:54 2 1 5 3Output:23 3 1 1 4 1 2 1 1 Given 4 2 1 5 3:Operation 0 : Parity = 0We split as (4 2 1) (5 3)New array : 5 3 4 2 1Operation 1: Parity = 1We split as (5) (3 4) (2) (1)New array : 1 2 3 4 5We get the sorted array.I am not able to prove why this works. I saw this pattern during contest but forgot about the case that k should not be equal to 1. Is this same as the approach given in the editorial intuitively ?
 » 4 years ago, # |   +5 This is what I did in problem D. Idea: for 1<=i
 » 4 years ago, # | ← Rev. 2 →   0 So we are basically optimising $O(n^2)$ dp solution for Problem C. My question is how do we optimize it if there is no $\triangle{t} \ge 2\cdot{r}$. Won't it run on $O(n^2)$ and give a TLE. Or am I missing something out? Thanks and Great Round. Edit : Got it. $t(i)  » 4 years ago, # | 0 I did come up with the$O(nr)$solution for 1427C - The Hard Work of Paparazzi, but I thought it would not fit into the time limit :(  » 4 years ago, # | 0 I use another optimization in problem C and also get accepted: 95139974 My brief idea is using ans[i] to store the maximum photos can be taken when we already at i'th celebrity. We iterate from ans[n] to ans[1]. For each ans[i], instead of iterating all celebrities in [i+1, n], we use a map to record the ans[j] (j in [i+1, n]) in descending order, so we can just take the first celebrity that satisfies$|x_i-x_j| + |y_i-y_j| \le t_j-t_i$.  » 4 years ago, # | 0 For problem C, is it possible that two consecutive celebrities appear at the same intersection? •  » » 4 years ago, # ^ | 0 That has to be true for any test case where n > r * r according to the pigeon hole principle.  » 4 years ago, # | ← Rev. 2 → +10 My solution for E: try various inputs, bruteforce and print some shit to get an intuitive understanding notice that the worst case is when$X$is a simple binary palindrome 1000...1 and we need to create numbers approx. up to$X^2$then we want to generate a smaller (than$X$) number$Y$; if it's even, we can remove the largest 1-bit from$X$using it, and if it's odd, we can solve recursively for$Y$(there's the operation limit, but this recursion turns out pretty fast) this seems to work for the palindromic case: try XORs of$X$,$2X$,$4X$etc. up to$2^k X$, for each$2^k$, pick one of these (denoted by$A$), then$B = A \oplus X$, then create$(A+B) \oplus (2A)$or$(A+B) \oplus (2B)$, and it turns out to be smaller than$X$for a good choice of$k \le 20$bruteforce check if it gives$Y \ll X$for each$X$it works and any odd$Y$is around 2 times smaller than$X$! implement I don't want randomised solutions because they carry a risk, but my thinking here is way more random. I have no idea why this works.  » 4 years ago, # | -18 I like problem D. And I believe I'm producing nicest solutions out of all solutions I've looked at. :) 95384262  » 4 years ago, # | 0 Anyone able to provide proof as to why we only need to consider 4r consecutive celebrities ? I'm not able to figure it out as I think, as said in the editorial, any element past the 2r point will be a compatible point. What different happens at 4r ?Thanks in advanced! •  » » 3 years ago, # ^ | +10 If the last celebrity you're choosing before celebrity$k$is celebrity$i
 » 3 years ago, # |   0 I have an alternate solution to problem E: doesn't use any number theory theorem.First of all, let's assume the number we have ends with $01$ and not $11$. If it ends with $11$, we can XOR it with its double and make it end with $01$. So we start from a number ending with $01$ : lets say we start from $x$.form a number $c$ which is $x$ shifted left $k$ number of times, where $k$ is the bit length of $x$.Then we XOR : $x+c$ and $x \oplus c$.Hence we get a number $d$ which is a pure power of $2$, and is the smallest power of $2$ which is greater than $x$.Now we will use this number $d$ to remove the highest bit of $x$: Keep multiplying $x$ by $2$, and whenever we have highest bit of $x$ and $d$ colliding, XOR them. Do it until only one bit in $x$ remains. Because $x$ ends with $01$, we get a power of 2 which is less than $d$. Use this to chop off the highest bit of $x$.Keep chopping off the highest bit of $x$ until we get $1$.Code