### chokudai's blog

By chokudai, history, 17 months ago,

We will hold AtCoder Beginner Contest 163.

The point values will be 100-200-300-400-500-600.

We are looking forward to your participation!

• +55

 » 17 months ago, # |   +32 Cannot access problems!!!
•  » » 17 months ago, # ^ |   +5 Click "tasks for printing" or here: https://atcoder.jp/contests/abc163/tasks_print, works for me even though the individual problem pages don't.
 » 17 months ago, # | ← Rev. 2 →   +23 Can't see the problem statements. :(Edit — Unrated. F
•  » » 17 months ago, # ^ |   +8 For the first 4 minutes, it just was giving Error 502, bad gateway, and now it is loading the problem but all I see is an area to submit code, the text of the task itself is invisible!!
•  » » » 17 months ago, # ^ |   0 Atleast they should make an announcement about how much delay to expect or something regarding to this.
 » 17 months ago, # |   +1 Can't see the problem statements only submit code is visible.
 » 17 months ago, # |   +5 contest is unrated .
 » 17 months ago, # |   0 Why Contest became Unrated?
 » 17 months ago, # |   +2 If someone wants to see the statements, press Ctrl + U and scroll the page down to the problem statement.
 » 17 months ago, # |   +9 What does 'internal error' mean?
•  » » 17 months ago, # ^ |   +3 Submit again it will give AC now!!
•  » » 17 months ago, # ^ |   0 It's AC now. your submissions
 » 17 months ago, # |   +11 Looks Like Atcoder is getting Inspired By CF
 » 17 months ago, # |   +2 Is the contest Unrated?
•  » » 17 months ago, # ^ |   +3 yes
•  » » 17 months ago, # ^ |   0 yes
•  » » 17 months ago, # ^ |   0 Yes. I'm unhappy to hear that because I solved 4 problems with penalty 27:58 and got the 1017 place. (；′⌒)
 » 17 months ago, # |   +11 scalability issue
 » 17 months ago, # |   +19 When E has more solver than A
•  » » 17 months ago, # ^ |   +6 orz first solver
•  » » » 17 months ago, # ^ |   +13 Actually, I didn't know that for a while, and after the contest become unrated, I saw it by chance. Because the page of problem A was not displayed I solved B first, and that was lucky. :)
 » 17 months ago, # |   0 How to solve D-F?
•  » » 17 months ago, # ^ |   +7 +1
•  » » » 17 months ago, # ^ |   +1 The solution for problem D: Sum of Large Numbers — here
•  » » » » 17 months ago, # ^ |   0 Good. Thanks a lot!
•  » » 17 months ago, # ^ |   0 my submission (problem D)
 » 17 months ago, # |   +43
 » 17 months ago, # |   +15 How to solve E?
•  » » 17 months ago, # ^ | ← Rev. 10 →   +35 Sort the children according to the Ai(from big to small)Then if you are considering the i-th child,this is always arranged in the smallest position (aren't used) or the biggest position (aren't used) .So we can dp.dp[i][j]means when considering the i-th child ,there are j children in the left ,the best answer.We can update it easily.UPDATE :SEARCH "Gary" in atcoder for the submission
•  » » » 17 months ago, # ^ |   +10 Can you explain dp transitions?
•  » » » » 17 months ago, # ^ |   +12 For the ith element after sorting, you need to place it in the front or at the back. And at this time (i — 1), elements have already been placed. L of them are in the front and R of them are at the back. Here L + R = i — 1.Then the dp transition is $dp[L + 1][R] = max(dp[L + 1][R], dp[L][R] + abs(L + 1 - pos[i]) * val[i]$ $dp[L][R + 1] = max(dp[L][R + 1], dp[L][R] + abs(n - R - pos[i]) * val[i]$Here pos[i] is the original position of the ith element, val[i] is its val.
•  » » » » » 17 months ago, # ^ |   +10 why not take the maximum distance for given Ai either front or back
•  » » » » » » 17 months ago, # ^ |   0 This was my doubt too. We are claiming to put the unassigned largest element at one of the extremes (I am guessing by thinking greedily?), then why not assign it to the farthest extremes. Can someone please clarify this?
•  » » » » » » » 17 months ago, # ^ |   0 That was my thought during the contest... But I guess one problem is : what do you do in case of equality ? If both extremes are of same distance to the current biggest element ? What extreme do you choose ? It's not an obvious question and the DP array allows you to see what happens to both extremes.
•  » » » » » » » » 17 months ago, # ^ |   0 Same thought came afterwards
•  » » » 17 months ago, # ^ |   0 Can you please prove why are we sorting in descending order.MrGary
•  » » » » 17 months ago, # ^ | ← Rev. 2 →   +7 If Ai>Aj!if i-th children and the j-th both move to the left,and the new j-th child's position is smaller.There are two cases i>j i
•  » » » » » 17 months ago, # ^ | ← Rev. 2 →   0 Thanks a lot for such a clear explanation
•  » » 17 months ago, # ^ |   0 The English tutorial for problem E: Active Infants is here
 » 17 months ago, # |   +1 How to solve F?
•  » » 17 months ago, # ^ |   +14 see HDU 6035 Colorful Tree, after erasing all nodes of color u, find all connected components of the remaining tree and minus the num of paths without passing color u. We can do it by using tree DP like the problem above in $O(n)$
•  » » » 17 months ago, # ^ |   0 Thanks a lot ^_^
•  » » » 17 months ago, # ^ |   0 My thought is also in the same lines as yours.can you please quote some references for the dynamic programming part. Finding it difficult to think.
•  » » » » 17 months ago, # ^ | ← Rev. 2 →   +6 I have solved this problem using dp.And the code is short and easy to understand.
•  » » » » » 17 months ago, # ^ |   0 Thank you.
•  » » » » » 17 months ago, # ^ |   0 can you please explain your solution.MrGary
•  » » 17 months ago, # ^ | ← Rev. 3 →   +27 I want to share my dumb solution. For a color with $M$ vertice, we can build a virtual tree containing the $M$ vertice in $O(M \log M)$. (Don't know if we can do better) Then simply DFS the virtual tree and calculate the number $K$ of paths in the original graph that doesn't contain the vertex in virtual tree. Te answer for that color is $\frac{n (n + 1)}{2} - K$.UPD: turns out it can be done in $O(M)$ since we don't need sorting in the problem code
•  » » » 17 months ago, # ^ |   0 Thank you.
 » 17 months ago, # |   0 I don't know if it was just me, but the website had full functionality in Firefox and not Chrome for the duration of the contest.
•  » » 17 months ago, # ^ |   0 true
•  » » 17 months ago, # ^ |   0 It's not about the particular browser as far as I understand Some of the responses from the server were cached in the browser during the heavy problems in the beginning. When you tried a different browser, it didn't have the same caches, so it worked fine. But you could just as well refresh the site ignoring the cache or reset it manually (ctrl-shift-R for me)
 » 17 months ago, # |   0 Is E maximum weighted bipartite matching problem. I have heard of the algorithm but don't know the algorithm.
 » 17 months ago, # |   0 I need help for problem D. Somebody help me! Why I got WA? here is the code.
•  » » 17 months ago, # ^ |   0 There is no need to mod in sigma and rsigma.
•  » » » 17 months ago, # ^ |   0 Oh, I see. I thought that it can't change the result because the property of modular arithmetic (a — b) % c == (a % c — b % c) % c. Could you elaborate on that?
•  » » » » 17 months ago, # ^ | ← Rev. 2 →   0 If you use mod in sigma and rsigma, the return value of rsigma maybe less than sigma, then you will get a negative number to add.
•  » » » » » 17 months ago, # ^ |   0 I got it. Thanks!
•  » » 17 months ago, # ^ |   0 https://atcoder.jp/contests/abc163/submissions/12138480This is my code for the problem. spookywooky has given the explanation for the problem.
•  » » » 17 months ago, # ^ |   0 Thank you!
 » 17 months ago, # | ← Rev. 3 →   +8 For D the key observation is, that for any set of $k$ choosen numbers, we can build any sum in the interval from smallest possible to the biggest possible.And those both numbers can be calculated in $O(1)$, so we can calculate the sum in $O(n)$.Min sum for $k$ of $n$ is $((i-1)\cdot i)/2$Max sum for $k$ of $n$ is $n\cdot i - ((i-1)\cdot i)/2$$ans=\sum\limits_{i=k}^{n+1}{max(i)-min(i)+1}$
•  » » 17 months ago, # ^ |   0 Can you tell why is max sum n*i — (i(i-1))/2. Like how a proof for that. Thanks :)
•  » » » 17 months ago, # ^ |   +1 we choose k numbers from (n+1) numbers (0, 1, ..., n). The min is 0 + 1 + ... + k — 1 = (k — 1) * k / 2 The max is n + (n — 1) + ... + (n — (k — 1)) = (2n — k + 1) * k / 2
•  » » » » 17 months ago, # ^ |   0 Thanks got it :)
•  » » » 17 months ago, # ^ |   0 That's simple. Take sum as (n-i+1)+(n-i+2)+....(n-i+i) --> the largest i elements. That will give you (n.i)-(i(i-1)/2).
•  » » 17 months ago, # ^ |   0 Thanks for explaining.
•  » » 17 months ago, # ^ |   0 great
 » 17 months ago, # |   +4 Can someone explain the recurrence and DP transitions in E?
•  » » 17 months ago, # ^ | ← Rev. 2 →   +4 I'll assume you already know that we should process the children from the biggest Ai first.Define dp[l][r] as the maximum happiness we can get if we want to put the remaining children to index l to r. The answer will be dp[1][N]. If the current state is (l, r), that means we are currently processing child with index i = N — (r — l + 1) + 1. We will have two choices, either put this child to index l or index r. If we put it to index l, then the happiness will be abs(l — child_initial_position) * A + dp[l + 1][r]. If we put it to index r, then the happiness will be abs(r — child_initial_position) * A + dp[l][r — 1]. We will take the maximum of those. Hope it helps.
•  » » » 17 months ago, # ^ |   0 how to be sure that maximum element should be in corners only?
•  » » » » 17 months ago, # ^ |   +3 You can use exchange argument technique to proof it. I am not really sure that my proof is correct, so I'll leave your question to someone more experienced.
•  » » » » » 17 months ago, # ^ |   0 What's exchange arguement technique. And can't E be done using maximum bipartitte matching.
•  » » » » 17 months ago, # ^ |   0 That's my question too?
•  » » » » 17 months ago, # ^ |   0 By rearrangement inequality, we can prove that, biggest element has to be multiplied with the biggest difference, which is possible only if we consider either extremes as its new position.
•  » » » 17 months ago, # ^ |   0 Thanks a lot for that explaination. Was really confused about this!
•  » » 17 months ago, # ^ |   +3 You can have a look at the English commentary of Problem E here.
•  » » 17 months ago, # ^ | ← Rev. 2 →   +1 take the sample 1 3 4 2 as example, the impact of every element in array should like this: [0, 1, 2, 3] [3, 0, 3, 6] [8, 4, 0, 4] [6, 4, 2, 0] it is easy to know that for every element, the impact of it is increasing whit itself like the element 4, the position is 3 then the effect of position of 4, 2, 1 is 4, 4, 8now you can see that like two element ai and aj, ai>aj, both ai and aj wants position k, we need to put ai at k because: first put all ai and aj to k: (ai*(k-x))+(aj*(k-y)) now we need to move one to k-1 because just one can put to k, if we move ai we need minus ai, move aj we need minus aj, because ai>aj, so put ai at k is better.
 » 17 months ago, # |   0 O(1) Solution for Problem D #include using namespace std; int main() { long long n, k; cin >> n >> k; cout << (2 * k * k * k - 3 * k * k * n - 6 * k * k + 3 * k * n - 2 * k + n * n * n + 3 * n * n + 8 * n + 12) / 6 % 1000000007 << endl; return 0; } 
•  » » 17 months ago, # ^ |   0 Can you tell me how you got this?
•  » » » 17 months ago, # ^ |   +1 Here is Explanation for the Formula
•  » » » 17 months ago, # ^ |   +1 $ans = \sum_{i = k}^{n} dp[i]$ $dp[i] = (\sum_{j=1}^{i} (n + 1 - j)) - (\sum_{j = 1}^{i} (j - 1)) + 1$Because all numbers between $\sum_{j = 1}^{i} (j - 1)$and $\sum_{j=1}^{i} (n + 1 - j)$(inclusive) are reachable.
 » 17 months ago, # | ← Rev. 3 →   0 What am I doing wrong in Problem D? codeIn my code, for sample case-1,ind = 0 1 2 3pre = 0 1 3 6suf = 6 6 5 3sum += (5-1+1) + (6-3+1) + (6-6+1) = 10`I am just calculating min and max sum using prefix and suffix sums, but this approach isn't working for sample case-3.
•  » » 17 months ago, # ^ |   0 In principle this is correct. There must be some of by one error, maybe caused by the fact that the first element in the set is 0.
•  » » 17 months ago, # ^ |   +1 mod=1e9+7.check it once
•  » » » 17 months ago, # ^ |   0 Well thanks! that was it. I'm stupid.
 » 17 months ago, # |   0 What's wrong?I can't see the statement!
•  » » 17 months ago, # ^ |   +1 Try using the tasks for printing feature: https://atcoder.jp/contests/abc163/tasks_print
 » 17 months ago, # |   +9 Can someone tell how to solve F?
 » 17 months ago, # |   0 Is this problem C? https://codeforces.com/problemset/problem/115/A
•  » » 17 months ago, # ^ | ← Rev. 2 →   0 Similar problem statement, but not same. In atcoder C, we just had to print the frequencies.
 » 17 months ago, # |   0 Can anyone please help me with problem E(active infants). I am just a beginner, i know that its a dp problem but still i am confused and not getting the actual transition states. Thankx in advance. God bless the helper!!
 » 17 months ago, # |   0 I finally passed a solution for F (in 1829 ms)!I realized the obvious technique of counting the sizes of the regions between two colors, doing the N*(N+1)/2 trick, and then complementary counting.However, my implementation was really messy (main code was nearly 200 lines long!).I ended up doing a pre-order traversal, and keeping track of a Binary Indexed Tree for each color. Any other ideas?