### awoo's blog

By awoo, history, 8 months 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

 » 8 months ago, # |   +42 Problem E was beautiful! Thanks :D
 » 8 months ago, # |   -9 Finally a contest with less ad-hoc!
 » 8 months ago, # |   0 past 2 contests have realised me that i'm more noob at maths than programming :(
•  » » 8 months ago, # ^ |   0 me too
•  » » » 8 months ago, # ^ |   0 Me Tooooooooooooo
 » 8 months ago, # |   0 Great Contest! Thanks
 » 8 months ago, # |   0 Too many Hacks for problem A . My solution was also hacked .
 » 8 months ago, # |   0 great contest. life is loop.
 » 8 months ago, # |   +89 contest is good but statement of E was awful
 » 8 months ago, # |   0 Isnt problem D much easier than problem C?
•  » » 8 months ago, # ^ |   -13 that's what she said : | : |
 » 8 months 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 
•  » » 8 months ago, # ^ |   +44 Excuse the use of Paint lol, but it looks something like this (the blue edges are the ones forming the cycle):
•  » » » 8 months ago, # ^ |   0 thanks !!
•  » » » 6 months ago, # ^ |   0 Can u please have a look why my solution for C is giving wrong answer for first test case , subtest 3 :( https://ideone.com/VlyDdV
 » 8 months ago, # |   +6 I think Problem D is simpler to use the Disjoint-set. Am I right?
•  » » 8 months 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
•  » » » 7 months ago, # ^ |   0 I did the exact same thing.. but my solution didn't work. Any edge cases I might be missing? My code
 » 8 months 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 :)
•  » » 8 months ago, # ^ |   +5 definitely an alt :rofl:
•  » » » 8 months ago, # ^ |   -10 Lol I took the idea from here
 » 8 months 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.
 » 8 months ago, # |   0 Can Anyone tell me how to solve question D recursively and doing memoization?
•  » » 8 months ago, # ^ |   0 Not by recursive dp, but Errichto explained the iterative dp approach in his yesterday's stream
•  » » » 8 months 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.
•  » » » » 8 months ago, # ^ |   0 You can solve it by recursion just reverse the starting position
•  » » 9 days ago, # ^ |   0 check my solution using memoization https://codeforces.com/problemset/submission/1476/128826229
 » 8 months ago, # |   0 For B, can anyone explain why there's a k-1 added to 100ll * p[i] - k * pSum?
•  » » 8 months 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
•  » » » 8 months 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
•  » » » » 8 months 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.
•  » » » 8 months ago, # ^ |   0 why we need to take the ceil.
•  » » » 8 months ago, # ^ |   0 Thank you for clarifying that. However, when I use ceil(100ll * p[i] - k * pSum), it says Wrong Answer. What is the reason for this? Also no one has used the in-built ceil function in their code. Please clarify if possible.
•  » » » » 2 days ago, # ^ |   0 You can have a look at my solution. Hope you it helps :) The way I have used the ceil function is more intutive. ~~~~~ #include #define fst ios_base::sync_with_stdio(false);cin.tie(0) #define all(x) (x).begin(),(x).end() #define int long long #define rep(i,a,b) for(int i=a;ib;i--) #define sz(x) (int)((x).size()) using namespace std; void solve(){ int n,k; cin>>n>>k; vector p(n); rep(i,0,n){ cin>>p[i]; } double t = (double)k/100; int s = p[0],ans = 0,diff = 0; rep(i,1,n){ double f = (double)p[i]/s; if(f > t){ int x = ceil((double)p[i]*100/k); diff = (x-s); ans += diff; s += diff; } s += p[i]; } cout<>t; while(t--) solve(); } ~~~~~
 » 8 months 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.
•  » » 8 months 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.
•  » » » » 8 months ago, # ^ |   0 Sure. What's your point?
•  » » » » » 8 months ago, # ^ |   -53 First of all, I have to wait for 10 minutes to comment, and second, you are cute (are you interested in unrated guys ??)
•  » » » » » » 8 months ago, # ^ |   -10 Can ya bitches stop being creepy to random ladies over the internet?
•  » » » » » » » 8 months ago, # ^ |   -38 you created an account just to comment on this. I respect that.
 » 8 months ago, # |   0 in the numerator why x = max(x, (100ll * p[i] — k * pSum + k — 1) / k); k-1
 » 8 months ago, # |   0 For E, why can't I topsort it?
 » 8 months ago, # | ← Rev. 3 →   -10 BledDest problem E : can there be a pattern which matches non of given string?i meant redundant pattern.Edit : yup!! that was silly,
 » 8 months 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.
 » 8 months ago, # |   0 couldn't you also have used two pointers in problem D (journey)?using two other pointers to find the longest distance you can travel to the left/right, and calculating if you are able to travel in the direction or not.the answer would be one plus the distance you can travel to the right and the distance you can travel to the left, as you would be able to travel back in any point in timemy solution
 » 7 months 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?
•  » » 7 months ago, # ^ | ← Rev. 2 →   +3 Your input is not correct. All patterns should be pairwise distinct.
•  » » » 7 months ago, # ^ |   0 Oh, many thanks! :)
 » 5 months ago, # | ← Rev. 2 →   0 For problem D, can someone let me know , how can i optimise it? i am getting tle on test case 14 https://codeforces.com/contest/1476/submission/113641003
 » 5 months ago, # |   0 in solution of problem b x = max(x, (100ll * p[i] — k * pSum + k — 1) / k); why we need to add k and minus 1 here k * pSum + k — 1
 » 4 months 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??
•  » » 4 months ago, # ^ |   0 I think it's the floor function that we have to take. If you are using c++, you simply have to do the calculation as to store a floating point number in an int data type, the number is automatically floored.
»
4 months ago, # |
0

# include<bits/stdc++.h>

using namespace std;

# define fo(i,l,r) for(int i=l;i<r;i++)

void solve(); int main() {

int t;
cin>>t;

while(t--)
{
solve();

}
return 0;

} void solve() { long long n,k; cin>>n>>k; if(n==k) { cout<<1<<endl; } if(n>k) { cout<<2<<endl; } if(n<k) { cout<<ceil((long double)(k)/(long double)(n))<<endl; } }  y is my code wrong for a?

•  » » 4 months ago, # ^ |   0 Anyone, please explain the binary search approach for 1476A - K-divisible Sum
•  » » » 3 months ago, # ^ | ← Rev. 2 →   0 //K-divisible Sum int main(){ long long int n,k,t,max,min; cin>>t; while(t--){ cin>>n>>k; if(n<=k){ if(k%n==0) cout<
•  » » » » 3 months ago, # ^ |   0 I asked for Binary Search!!
 » 3 months ago, # |   0 what is cf in problem A??
 » 3 months ago, # |   0 Problem B : Inflation. int n =sc.nextInt(); double k =sc.nextDouble(); `double a[] = new double[n]; for(int i=0;i
 » 7 weeks ago, # |   0 Can anybody explain B? I couldn't understand even after reading the tutorial. Thank you in advance.
 » 6 weeks ago, # |   0 Can D be solved using binary search?Submission Getting TLE on test14.