### awoo's blog

By awoo, history, 13 months ago, translation,

1519A - Red and Blue Beans

Tutorial

1519B - The Cake Is a Lie

Tutorial

1519C - Berland Regional

Idea: BledDest

Tutorial
Solution (awoo)

1519D - Maximum Sum of Products

Idea: vovuh

Tutorial
Solution (Neon)

1519E - Off by One

Idea: BledDest

Tutorial
Solution (awoo)

1519F - Chests and Keys

Idea: BledDest

Tutorial
Solution (BledDest)

• +92

 » 13 months ago, # |   +5 Here is a problem which has the same idea with D. http://acm.hdu.edu.cn/showproblem.php?pid=6103
•  » » 13 months ago, # ^ |   0 Are you a chinese person?
 » 13 months ago, # | ← Rev. 2 →   0 Anyone knows why there's a major difference between predicted and actual rating changes?
•  » » 13 months ago, # ^ |   0 At least in my case the predictor was using my rating from 2 contests prior. I think it must have scraped the ratings at a time when ratings changes were rolled back.
 » 13 months ago, # | ← Rev. 2 →   +1 Can anyone help me in identifying the mistake in Problem D, the approach is similar to the longest palindromic substring. It is failing in the 11th test case.Link to the submission: https://codeforces.com/contest/1519/submission/114709341Edit: the issue is resolved thanks
•  » » 13 months ago, # ^ |   0 Use vector for a and b, because the when you multiply two int's, the compiler doesn't know to convert it to a long long unless you explicitly tell it to do so, or have the types originally as long long's.
•  » » » 13 months ago, # ^ |   0 Yeah thanks a lot
 » 13 months ago, # |   0 Aren't problems like E and F suitable better for div1? Why not use them in div1 then as creating div1 problems is harder.
•  » » 13 months ago, # ^ |   +14 Can't comment about F but problems like E are repeat or too obvious for Div1 contenders.
 » 13 months ago, # |   +27 Thanks for E, it was quite educational.
•  » » 13 months ago, # ^ |   0 i couldn't keeep upto editorial of E after dfs tree. Can you explain what they mean by dfs tree and what after that.Thanks in advance.
•  » » » 13 months ago, # ^ |   0 This is a very nice dfs tree entry: https://codeforces.com/blog/entry/68138
 » 13 months ago, # | ← Rev. 2 →   +1 Can anyone explain how the time complexity of C is nlogn
•  » » 13 months ago, # ^ |   0 The time complexity is nlogn because you must to sort the elements of each university before the calculation of the prefixes.
•  » » » 13 months ago, # ^ |   0 But for each k from 1..n we calculate the result, which requires to go through all schools from 1..n. Doesn't it give n^2?
•  » » » » 13 months ago, # ^ |   0 On each university we iterate between the values 1 and the number of students in that university, because for higher values the university can not make a team. This has a complexity of O(n).
•  » » » » » 13 months ago, # ^ |   +1 thx, now I get it
 » 13 months ago, # |   0 Very interesting contest, I really enjoyed it! Thanks!
 » 13 months ago, # | ← Rev. 3 →   +3 can anyone explain how forward edges are handled in last paragraph of editorial of E?upd: got it
 » 13 months ago, # |   0 Will the rating roll back QAQ
 » 13 months ago, # |   0 can anyone show me simple readable solution for C?
•  » » 13 months ago, # ^ |   0
•  » » » 13 months ago, # ^ |   0 thanks. yeah!,white house clean
 » 13 months ago, # |   0 Can someone please give me a proof for B?
•  » » 13 months ago, # ^ |   0 You can also use BFS
•  » » » 13 months ago, # ^ |   0 Sadly haven't got to covering this yet, trying to solve most of the A problems and B problems from Div2 90% before I go on to covering DP, DFS and BFS problems. If you could tell me a way to prove this without assuming the formula, that would be amazing.
•  » » » » 13 months ago, # ^ |   0 No one directly "assumed" the formula in my opinion how I approached it was trying to convert my intuition to mathematical proof. Try reading this article. Have a good day!
•  » » 13 months ago, # ^ |   0 Try to draw a 2d matrix and try to compute the value at random points from taking both ways left and right then u will come up with the same formula
•  » » » 12 months ago, # ^ |   0 Alright. Thank you
 » 13 months ago, # |   0 the round was amazing, can anyone help me identify the error in 114652844 to problem c, my approach is similar to the edi.
•  » » 13 months ago, # ^ |   0
 » 13 months ago, # | ← Rev. 2 →   0 Short Video Editorial For Problems A — D I have a different solution for problem D (Maximum Sum of Products): $sum[i][j]$ stores the new sum on reversing the subarray $[j, i]$ $sum[i][j] = sum[i - 1][j + 1] + A[i] * B[j] + A[j] * B[i]$ We calculate the sum of elements we get on reversing every subarray $[j, i]$. To account for the rest of the array, loop over all subarrays and use prefix sums to add the remaining part. Take the best value over all subarrays. Time complexity: $O(N^2)$ See my code for clarity: 114583311
•  » » 13 months ago, # ^ |   +6 They're actually the same
•  » » 13 months ago, # ^ |   0 why did you take max(dp[i][j], dp[i — 1][j + 1] + A[i] * B[j] + A[j] * B[i]), what's the use of taking maximum here??
•  » » » 13 months ago, # ^ |   0 Yeah, you're right. There's no use of doing that here.
 » 13 months ago, # |   0 hi! can some one point out my mistake in D. I have used the same approach as in editorail, except i have used a 2-D dp. test case 27 is showing wrong answer. https://codeforces.com/contest/1519/submission/114798610 thanks
 » 13 months ago, # |   0 Hi, for problem C, can somebody explain why 114796728 gives TLE and 114799663 doesn't. The only difference is the usage of an array instead of a vector.
•  » » 13 months ago, # ^ |   0 when you are declaring:vll pre(n+1),i dont why but on my system it fills it with garbage value, and run time is really slow on my pc as you have statedbut,when u use ll pre[n+1] ,pre is filled with all 0s, and run time is fast on my pc
•  » » 13 months ago, # ^ |   +1 Your code is fundamentally O($n^2$) because of f(i,1,n+1) { vll pre(n+1); As far as I can tell, the only reason why you didn't TLE on your 2nd submission is because the compiler was nice and effectively optimized your code to vll pre(n+1); f(i,1,n+1) { Some other things I noticed about your code: Remove cout.tie(NULL) from your code. Unlike cin.tie(NULL); the cout version does nothing and should never be used. Submit under C++17(64 bit) instead of C++11. You will see much better running times. You are basically handicapping yourself by using C++11.
•  » » » 13 months ago, # ^ |   -6 Thanks, I'll take note of it.
 » 13 months ago, # |   0 Can anyone help me figure out why I am getting TLE (https://codeforces.com/contest/1519/submission/114826178)
•  » » 13 months ago, # ^ |   0 Hey, I tried your approach as well, calculating answer for each value of k[1,n] , i got TLE as well, link similar to your solution(TLE): https://codeforces.com/contest/1519/submission/114824539Nevertheless, I got ACC , finally. Here's some tips, i can give you:1.) use vector instead of map db or use unordered_map2.) use a vector to store output of each value of k[1,n]3.) after sorting the inner vector, use the same inner vector to store cumulative sum 3.) iterate this inner vector after sorting and increment the value of output-vector according to this inner vectormy Accepted solution(not the most efficient): https://codeforces.com/contest/1519/submission/114825135
•  » » » 13 months ago, # ^ |   0 thanks
•  » » 13 months ago, # ^ | ← Rev. 6 →   0 Your code failed only because you used iterator as the second loop. The same reason my code failed and changing it will surely give AC. I also changed map to vector first and all the other optimizations and still it failed but this one small change gave AC. Reason why this happens is because when n >= 10^5, iterator being nested will be called in range of 10^5 times(depending on implementation). At this range it becomes really slow compared to normal for loop with [] operator. In my tests above 10^5 it was almost 1.2 — 2 times slower in this question(Can be more/less as I did these tests on my own PC but you can get the idea).Check the running time in both these codes where the only difference is for loop instead of for-each(uses iterator)Accepted Code — https://codeforces.com/contest/1519/submission/114687960
•  » » » 13 months ago, # ^ |   0 thanks
•  » » » 13 months ago, # ^ |   0 https://codeforces.com/contest/1519/submission/114986969can you figure out why am i still getting TLE?
 » 13 months ago, # |   0 Can Any one help me in Problem D, i used BIT to calculate the prefix and suffix value and used Brute force for calculating the interval [i,j] , but still TLE at test case 9:
 » 13 months ago, # | ← Rev. 2 →   0 for problem D, if I try to implement the brute force approach which would take O(n^3) time then will it be TLE ? As the constraint is n <= 5000.
•  » » 13 months ago, # ^ |   0 Yes it would TLE as (5000)^3 = 125*10^9=1.25*10^11 As this is much greater than the recommended 10^9 it would not fit within the time limit and give a TLE error.
•  » » » 13 months ago, # ^ |   0 Thanks a lot
 » 13 months ago, # |   0 Can anyone Explain D a little bit in detail
•  » » 13 months ago, # ^ |   0 I am sure this will help Video
•  » » » 13 months ago, # ^ |   0 Love the explanation. Thanks. Cleared all the doubts
 » 13 months ago, # |   0 What does if(nw.need == vector(a, a + n)) in F's solution mean?
 » 13 months ago, # |   0 I believe I tried to solve with the same approach as explained in the editorial for C . i.e grouping the students according to university_id and then taking the prefix sum for individual university . however I kept getting TLE on test 4 . can anyone tell why ? 114624170
•  » » 13 months ago, # ^ |   0 I have got the same issue .. try to sort the vector of vector in terms of size of v[i].size in greater(). Uh can check out my code too .. i can explain that
•  » » » 13 months ago, # ^ |   0 why does erasing gives TLE ?
•  » » » » 13 months ago, # ^ |   0 Erasing what ?
•  » » » » 13 months ago, # ^ | ← Rev. 2 →   0 Erasing an arbitary element from a vector takes $O(n)$, since all elements after the deleted element need to be shifted.
 » 13 months ago, # |   0 Please explain the proof for problem B little more briefly.. Why doesn't the cost depend on path taken?
•  » » 13 months ago, # ^ |   +5 Consider the two paths shown in the picture below: one which takes the blue route and one which takes the red route. The black parts of the two paths are the same in both paths.Either way, the contribution from the red section or the blue section is $+(i+j)$, so both paths have equal cost.You can change from any path to any other path via a sequence of paths which each differ only by one square, like in the picture above.
•  » » » 13 months ago, # ^ |   0 Thank you very much. I get it now!
 » 13 months ago, # |   0 Can anyone help me out in c question i had also used prefix sum but getting tle on 4 th case but it should not come 115057482
•  » » 13 months ago, # ^ |   +2 You must be missing tricky point. Check this explanation
 » 13 months ago, # |   0 I believe there is a typo in the editorial for F: instead of $\sum_{i=1}^{a_i} - mincut$ it should be $\big(\sum_{i=1}^n a_i\big) -mincut$.
 » 13 months ago, # |   0 $2$ more proofs for problem $B$:Mathematical proof:Assume that the sequence of movement is as follows: $x_1$ units down, then $y_1$ units right, then $x_2$ units down, then $y_2$ units right, ..., then $x_c$ units down, then finally $y_c$ units right, where $x_i, y_i \geq 0$, $1+\sum_{i=1}^{c}x_i=n$, and $1+\sum_{i=1}^{c}y_i=m$. The total cost will be:$x_1*1+y_1*(1+x_1)+x_2*(1+y_1)+y_2*(1+x_1+x_2)+...+(1+\sum_{i=1}^{c-1}y_i)*x_c+(1+\sum_{i=1}^{c}x_i)*y_c=$$\sum_{i=1}^{c}y_i+\sum_{i=1}^{c}x_i*(1+\sum_{i=1}^{c}y_i)=m-1+(n-1)*m=n*m-1$Ad hoc proof:A step from $(i,j)$ to $(i+1,j)$ spans all the cells from $(i+1,1)$ to $(i+1,j)$, and a step from $(i,j)$ to $(i,j+1)$ spans all the cells from $(1,j+1)$ to $(i,j+1)$. Which means that for every step down to a cell $x$, all the cells from $x$ to the left will be counted, and for every step right to a cell $y$, all the cells from $y$ to the top will be counted. At the end, all the cells in the grid will be counted except the first cell $(1,1)$, that is $n*m-1$.
 » 13 months ago, # |   0 Can anyone tell me why this code is giving me tle :( but after reversing the conditions of last for loop it got accepted......Thanks in Advance :)#include using namespace std; int main(){ int t; cin >> t; while(t--){ int n; cin >> n; vector uni(n); vector score(n); vector combine(n,vector()); for(int i=0;i> uni[i]; } for(int i=0;i> score[i]; } for(int i=0;i()); } for(int i=0;i0) ans+= combine[j][x*i-1]; } cout << ans << " "; } //But after making this change All Ok :) vector ans(n,0); for(int i=0;i
 » 12 months ago, # | ← Rev. 3 →   0 Hi awooFor problem F, using the idea of saturating all out going edges from source to chests, I used this dynamic programming state : dp[i][j][a][b][c][d][e][f] = the minimal cost to saturate the first i out going flow edges from source, where the i-th out going edge currently has j units of residual remaining, and the 1st incoming edge to sink has a units of residual left , second incoming edge to sink has b units left , 3rd has c units left, 4th, 5th, 6th have d , e , f units left respectively. base case: dp[0][0][a][b][c][d][e][f] = 0 , for all a,b,c,d,e,f <= 6 transition: dp[i][j][a][b][c][d][e][f] = min{ dp[i][j - min(j , a)][a - min(j , a)][b][c][d][e][f] + C[i][1], dp[i][j - min(j , b)][a][b - min(j , b)][c][d][e][f] + C[i][2], dp[i][j - min(j , c)][a][b][c - min(j , c)][d][e][f] + C[i][3], dp[i][j - min(j , d)][a][b][c][d - min(j , d)][e][f] + C[i][4], dp[i][j - min(j , e)][a][b][c][d][e - min(j , e)][f] + C[i][5], dp[i][j - min(j , f)][a][b][c][d][e][f - min(j , f)] + C[i][6], } `Here is my submission https://codeforces.com/contest/1519/submission/116235067 I got wrong answer on test case 93, I have been trying to find the bug for a day and could not resolve it. You will be my life saver if you hint me on why my solution did not get AC!