Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

### awoo's blog

By awoo, history, 3 years ago, translation,

1476A - K-divisible Sum

Idea: vovuh

Tutorial

1476B - Inflation

Tutorial

1476C - Longest Simple Cycle

Tutorial

1476D - Journey

Idea: BledDest

Tutorial
Solution 1 (BledDest)
Solution 2 (BledDest)

1476E - Pattern Matching

Idea: BledDest

Tutorial
Solution 1 (awoo)
Solution 2 (awoo)

1476F - Lanterns

Idea: BledDest

Tutorial
Solution (BledDest)

1476G - Minimum Difference

Idea: Neon

Tutorial
Solution (Neon)
• +143

| Write comment?
 » 3 years ago, # |   +42 Problem E was beautiful! Thanks :D
 » 3 years ago, # |   -9 Finally a contest with less ad-hoc!
 » 3 years ago, # |   +89 contest is good but statement of E was awful
 » 3 years ago, # |   +3 In problem C , How the value of the following test case will be 6? please explain.. input 3 2 4 2 -1 2 4 -1 2 1 output 6 
•  » » 3 years ago, # ^ |   +44 Excuse the use of Paint lol, but it looks something like this (the blue edges are the ones forming the cycle):
 » 3 years ago, # |   +6 I think Problem D is simpler to use the Disjoint-set. Am I right?
•  » » 3 years ago, # ^ |   +6 It can be done simply by moving from current city to Right to find the largest pattern of RL...RL or RL...RLR and similarly on left from current city to left as LR...LR or LR...LRL and length of both the patterns + 1 will be the max cities visited from current cityYou can see my solution : https://codeforces.com/contest/1476/submission/106090614
 » 3 years ago, # | ← Rev. 2 →   0 This was a very nice contest after a while. Kudos to the authors, each and every problem in the contest that I solved / up-solved taught me something new. Hope for more such rounds :)
•  » » 3 years ago, # ^ |   +5 definitely an alt :rofl:
 » 3 years ago, # | ← Rev. 2 →   +8 Can someone help me figure out the error of code for submission below? My Code Here is my code for problem F. It gets wrong answer on test 5, case 1259. However, I can't get that sample.
 » 3 years ago, # |   0 Can Anyone tell me how to solve question D recursively and doing memoization?
•  » » 3 years ago, # ^ |   0 Not by recursive dp, but Errichto explained the iterative dp approach in his yesterday's stream
•  » » » 3 years ago, # ^ |   0 No like I am asking like can we solve it that way(recursive dp) like I am stuck and unable to move forward in my approach.
•  » » » » 3 years ago, # ^ |   0 You can solve it by recursion just reverse the starting position
•  » » 2 years ago, # ^ |   0 check my solution using memoization https://codeforces.com/problemset/submission/1476/128826229
 » 3 years ago, # |   0 For B, can anyone explain why there's a k-1 added to 100ll * p[i] - k * pSum?
•  » » 3 years ago, # ^ |   +1 It is basically done to take ceil of the value.Let me make it more clear — Ceil(a/b) == (a+(b-1))/b You can check this by taking two cases - a = k*b. Both functions return k a = k*b + x (0
•  » » » 3 years ago, # ^ |   0 but in editorial he didn't mention the ceil thing i understand it from the code but i dont understand the purpose of it, if u can explain please
•  » » » » 3 years ago, # ^ |   0 It is mentioned in the editorial that -$x \ge \left\lceil \frac{100 \cdot p_j - k \cdot (p_0 + \dots + p_{j - 1})}{k} \right\rceil$Notice the bracket, that is for denoting ceil function.Now the next question is why do we even need that — because x is a non negative integer and right hand side acc. to maths will return a floating value (which may not be integer). Let's take an example — You know x is an integer and after solving RHS you get - $x \geq 1.2$So definitely you know you should pick next integer (ceil value) as answer i.e. x = 2.
 » 3 years ago, # |   +1 A constant optimization for 1476G - Minimum Difference -- observing that the upper bound of value $c$ always equals to the lower bound of $(c + 1)$, we can store only the lower bounds (but not both as in the model solution), You can see my submission 106048247 for the detail.
•  » » 3 years ago, # ^ |   +13 There is no need of segment trees for 1476F - Lanterns. We need only two operations: The one is to query $\max\{(j + p_j), \dots, (i + p_i)\}$ for increasing $i$. The other one is to find the minimum $j$ where $\mathrm{dp}[j] \geq i - p_i - 1$. The two operations can be supported by two standard (monotonic) stack and std::lower_bound. My submission 106219219.
•  » » » 3 years ago, # ^ |   -39 forget about this stupid problem is your profile photo-real ??
•  » » » » 3 years ago, # ^ |   0 Sure. What's your point?
•  » » » 23 months ago, # ^ |   0 Hello, can you take a look at my submission for problem F Lanterns.I have not used a segment tree but a sparse table and for each lantern(let us say i) that points to the left, I have kept a pointer to the last lantern(let us say j) such that the lanterns 1 to j cover some continuous segment of lanterns not covered by the lantern i.I am failing at some 1200+ subtest of test case 5 and will be much thankful if you can help me point out where my algorithm fails. Or if you can provide some test case where it fails?Any help will be much appreciated. Thanks!
 » 3 years ago, # |   0 For E, why can't I topsort it?
 » 3 years ago, # |   +3 In E you can also find a match converting the string to integer. The number of possible strings is $27^k$, so every pattern can be indexed.
 » 3 years ago, # |   0 Question for problem EInput 4 4 4 aaaa aaaa aaaa aaaa aaaa 2 aaaa 2 aaaa 2 aaaa 2 The solution's output is "NO", but I think 2 1 3 4 is right, do I understand the problem wrong?
•  » » 3 years ago, # ^ | ← Rev. 2 →   +3 Your input is not correct. All patterns should be pairwise distinct.
•  » » » 3 years ago, # ^ |   0 Oh, many thanks! :)
 » 3 years ago, # |   0 In the first problem, I did the same thing with ceil function but it threw wrong answer...How is it possible to get the correct answer by just using ceil in a different mathematical way as shown in tutorial??
 » 23 months ago, # |   0 My code to F Lanterns fail at some 1200+ test of test case 5. Can someone take a look at my submission and guide me to where my code's failing? Or provide a test case where it fails?Help will be much appreciated. Thanks!
 » 15 months ago, # |   0 How A is binary search? somebody, please explain.
•  » » 11 months ago, # ^ | ← Rev. 2 →   0 find the smallest number greater than= n which is divisible by k.. search space is from n to 1e9. as the elements are positive each one can be minimum 1. each element can be minimum 1.
•  » » 11 months ago, # ^ |   0
•  » » 11 months ago, # ^ |   0 find the smallest number greater than= n which is divisible by k.. search space is from n to 1e9. as the elements are positive each one can be minimum 1. each element can be minimum 1.
 » 7 months ago, # |   0 For Problem C, Could someone please explain why the answer to the following test case is 8?3 3 5 2 -1 1 1 -1 3 5
•  » » 5 months ago, # ^ |   0 Nevermind, I think I got it
 » 3 months ago, # |   0 how to solve A problem using binary search?
 » 2 months ago, # |   0 For problem F, there also exists another dp.For any $i$, we will assume that we use only the first $i$ lanters, and define $dp(i, j)$ to be the maximum possible value of $(i + p[i])$ among all right-facing lanterns in the first $i$ lanterns, if the $j$'th ($j < i$) lantern is the leftmost uncovered lantern.Transitions are somewhat similar to the editorial, but we require only one segment tree instead of two.Implementation: link