### chokudai's blog

By chokudai, history, 15 months ago,

We will hold AtCoder Beginner Contest 203（Sponsored by Panasonic）.

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

We are looking forward to your participation!

• +43

 » 15 months ago, # |   -31 Why does the problems in AtCoder are so math oriented?
 » 15 months ago, # |   0 Oops...It's Clashing with May Starters on Codechef!
•  » » 15 months ago, # ^ |   +63 You better say, May Starters is clashing with ABC 203.
 » 15 months ago, # | ← Rev. 2 →   +26 Why is spacing of parentheses so weird on AtCoder?
 » 15 months ago, # |   +13 Somebody want to show how the dp works in D?
•  » » 15 months ago, # ^ |   +19 I used binary search on the median.
•  » » » 15 months ago, # ^ |   0 can you elaborate i was also doing same but did not got AC.
•  » » » » 15 months ago, # ^ | ← Rev. 2 →   0 I have elaborated the approach over here — https://codeforces.com/blog/entry/91245?#comment-797573I hope this helps, do let me know if anything is not clear.Here is the implementation of the same — Code
•  » » » » » 15 months ago, # ^ |   0 Can you share your code?
•  » » » » » » 15 months ago, # ^ |   0 Updated the comment!
•  » » » » » 15 months ago, # ^ |   0 can you please explain C
•  » » » » » » 15 months ago, # ^ |   +1 Sort the pairs $(A_i, B_i)$ according to $A_i$Start iterating through them, when you are on $A_i$, add $B_i$ to your $currentYen$, then check whether you can reach $A_{i + 1}$ using the yen you currently have or not, if not, break the loop, otherwise keep iterating.You can check the code for better understanding — Code
•  » » » » » 15 months ago, # ^ |   0 Question — this only showed up as question D in a beginner's contest. which suggests probably E and F were even harder (I did not get to them yet). Question D seems quite hard already — is it representative of the level required at the beginner's contests? Is this question pretty standard / repetitive or are you expected to come up with the binary search approach when you see this for the first time?..
•  » » » » » » 15 months ago, # ^ |   +3 I have already seen questions where binary search is applied like this, that's why I was able to come up with the approach. While this technique is not very common, but you see questions based on this every once in a while. Honestly, I wouldn't be able to come up with this approach if I was seeing a question like this for the first time. Regarding E and F being difficult, in my personal opinion, I found E easier than D. Usually D is easier than this in ABCs
•  » » » » » » » 15 months ago, # ^ | ← Rev. 3 →   +3 Thanks for your feedback! I attempted D with an order statistic set (+taking care of duplicates) but the time complexity was still not good enough :-) Managed to work my way through the idea behind the binary search solution now — here's my Java take: https://atcoder.jp/contests/abc203/submissions/23100690
•  » » » » 15 months ago, # ^ | ← Rev. 2 →   +15 For some $x$ check that if the answer is $\leq x$.Mark all the elements with value $\leq x$ to $1$, otherwise $0$.Let $t = \lceil \frac{k \times k}{2} \rceil - 1$.Now if there exists some $k \times k$ square with sum $\geq t$ then Yes otherwise No.
•  » » » » » 15 months ago, # ^ |   0 Can anyone suggest a few problems with the same or similar concept of replacing some elements with 0 and 1?
•  » » » » » » 15 months ago, # ^ |   +4 Problem You may try this!!
•  » » » » » » » 15 months ago, # ^ |   0 Thanks!!
•  » » » » » » 15 months ago, # ^ |   +3 https://codeforces.com/problemset/problem/1201/C This is another nice one.
•  » » » » » » » 15 months ago, # ^ |   0 Thanks, really nice problem
•  » » » 15 months ago, # ^ |   +4 I thougt about if I can somehow use binary search... but actually have no clue how to do it in that problem.
•  » » » » 15 months ago, # ^ |   +4 It was a kinda weird binary search, but what I did is I used prefix sums to query the sum in the square range, and the grid that I did prefix sum on was $1$ if a[i][j] <= check else $0$. If the sum in that square range is >= (k*k+1)/2, then it's a possible median. Otherwise it isn't.
•  » » » » » 15 months ago, # ^ | ← Rev. 2 →   0 deleted
 » 15 months ago, # |   0 How to solve D
•  » » 15 months ago, # ^ | ← Rev. 3 →   +14 Binary Search the answer. At each step of binary search make a binary array with 1 if $a[i][j]<=mid$ or else zero. If one of the all possible $k*k$ squares exceeds $(k*k)/2$, it means that a median <= mid is possible. You can check sum of each square using prefix sum
•  » » 15 months ago, # ^ |   +5 binary search for median.
•  » » 15 months ago, # ^ |   +7 I used binary search to find the answer. Let $mid$ be the chosen value, I will modify my array, where any $a[i][j] > mid$ will be $1$ in and all others will be $0$, after that just check whether the sum of any $K*K$ block is less than $(K * K) / 2 + 1$, if it is, $mid$ can be a possible answer. To find the sum of a $K * K$ square, you can use prefix sums.
•  » » » 15 months ago, # ^ |   +3 Only prefix sum, I needed kind of dp. How did you do that?https://atcoder.jp/contests/abc203/submissions/23059605
•  » » » » 15 months ago, # ^ |   0 https://atcoder.jp/contests/abc203/submissions/23057631Same implementation, I even named the variable as dp xD I refrained from saying it was dp since some people might feel I am talking about something much more complex
•  » » » » » 15 months ago, # ^ |   +3 Thank you, very clean and understandable solution
•  » » » 15 months ago, # ^ |   0 Can you briefly explain why that is working ? if (val < medianValue) { retValue = true; }
•  » » » » 15 months ago, # ^ | ← Rev. 2 →   0 For a particular mid let's say mid1, if any block has a sum less than the medianValue, that means, if all the numbers which are currently assigned as 0, were equal to mid1, then mid1 would've been the median. We don’t know for sure whether this was the case or not, so we are considering mid1 to be a candidate for the answer. Now, when we consider a smaller value for mid, let's say mid2, if for the same block, even mid2 returns a sum less than the medianValue, then we can say that our assumption was wrong and instead of mid1, mid2 is the next possible candidate for the answer. This is also in accordance with the question which wants us to find the lowest median value.
•  » » » » » 15 months ago, # ^ |   +3 Perfect! Thanks a lot.
•  » » » 15 months ago, # ^ |   +3 This is Awesome dude!
 » 15 months ago, # |   +18 We can solve E by maintaining a set of all possible column positions of the white pawn, then iterate the black pawns sorted by row.Foreach black pawn, we can move to the column of the black pawn if the col of it +-1 is in the current list of columns, and we need to remove the column from our list if both of the +-1 columns are not in the list.We need to take care that there can be multiple black pawns in one row, we need to consider them "all at once".submission
•  » » 15 months ago, # ^ | ← Rev. 2 →   +3 Damn, that is exactly what I did. I wonder what went wrong SubmissionEdit: Thanks guys, I realised I should've erased after going through all elements in a particular x coordinate :(
•  » » » 15 months ago, # ^ | ← Rev. 2 →   0 You are erasing from s while iterating over c, which can lead to erasing of an element that might be helpful for some future element in c.
•  » » » 15 months ago, # ^ |   0 Consider two black pawns next to each other, and the col of the left one in the current list.You remove the left position, then cannot consider that it can be moved to the right position.
•  » » » 15 months ago, # ^ |   0 From a quick glance, I think about a case where we have 2 black pawns ( 1, N ) and ( 1, N.+ 1). Currently, we remove ( N ) from the relevant list before ( 1, N + 1 ) is processed
•  » » 15 months ago, # ^ |   0 Before, I saw your code, I thought it would be quite implementation heavy. Thanks for the brillaint short code!
•  » » 15 months ago, # ^ | ← Rev. 3 →   0 Got it thanks
•  » » » 15 months ago, # ^ |   0 The rules of moving the white pawn are like in the chess game. A black pawn is not like a rock, it is a pawn that can be captured. The rule says that this is possible if going diagonal, like from 0,2 to 1,1.In the case we want to go from 0,1 to 1,1, a black pawn acts like an obstacle.
•  » » » » 14 months ago, # ^ |   0 Can you please help me out. I am not able to find my mistake. code Thanks!
•  » » » » » 14 months ago, # ^ |   0 "...we need to consider them "all at once".Cosider two black pawn next to each other in one row. That does not work in your code.
•  » » » » » » 14 months ago, # ^ |   0 Thanks! It worked.
 » 15 months ago, # |   +11 How to do F?I tried dp[i][j]: max elements takahashi can take from first i smallest elements in j steps, not sure what went wrong.
•  » » 15 months ago, # ^ |   +11 Max Number of moves is less than $30$. We can make the number of moves as one of the dimensions of dp and calculate the minimum possible removals required for a fixed number of moves.
•  » » » 15 months ago, # ^ | ← Rev. 2 →   0 Nvm, got it.
•  » » » » 15 months ago, # ^ |   0 Sorry as the official editorial is not out yet, can u pls explain ur thought process now a bit briefly...Also pardon me for asking but can u also link ur sol. (or maybe say ur id so that I can learn/understand from your code). Ty.
 » 15 months ago, # | ← Rev. 2 →   0 UPD: Fixed, it was a problem with the Comfortable Atcoder extension, I removed it and then everything worked like normal.Not sure if this is a bug or something on my end, but whenever I open a page on Atcoder (except for a few exceptions), it open it in Japanese and I have to change it every time. I checked my settings and I have "USA" selected, so I'm not sure if I have to change anything else.I looked at the link differences, and there's a ?lang=en at the end when a page is in English. Maybe there could be a setting, like "Preferred language"?
•  » » 15 months ago, # ^ |   0 The language preference seems to be stored in a Cookie (namely language cookie), so there may be a issue with the Cookie settings.
 » 15 months ago, # | ← Rev. 3 →   0 Did someone solve D by maintaining a set/multiset for each square and finding kth largest for each query using pbds or something?
•  » » 15 months ago, # ^ |   0 I tried... TLE galore :D
•  » » 15 months ago, # ^ |   0 Me tooI thought maybe if I convert it to c++ it will work, but apparently no :P
 » 15 months ago, # | ← Rev. 2 →   0 I tried to do bfs in E, from any pawn to any other reachable pawn. This costed me heavy implementation and of-course, 2 minutes passed after the contest sadly.https://atcoder.jp/contests/abc203/submissions/23074189Edit: I accidentally copied another submission lol
•  » » 15 months ago, # ^ |   0 That's spookywooky's submission 69 (nice) minutes into the contest, which lasts 100 minutes.
•  » » » 15 months ago, # ^ |   0 Lol, my bad. Added my one.
 » 15 months ago, # | ← Rev. 2 →   0 Can anybody explain the last test case of problem F Weed 3rd test case9 8137 55 56 60 27 28 133 56 55
•  » » 15 months ago, # ^ |   0 Aoki can choose Weeds 137, 133, 28 and 27. Then Takahashi will take 60, 56, 56, 55, 55 in one go. So the answer will be 1 4.
 » 15 months ago, # |   0 In prob C, I call vis the current village Taro is standing in, k is the amount of money he has, why is the furthest village he can go to is vis+=k but not k+= vis ? I got AC with vis+=k in submission:but WA with k+=vis in submission:in both cases, all examples tests are passed. Please give me a clue, thank you.
•  » » 15 months ago, # ^ |   0 k is defined as ll, vis as int which causes overflow.
•  » » » 15 months ago, # ^ |   0 Thank you so much. I got it.
 » 15 months ago, # |   0 is there a way to see test cases for this contest (atcoder beginner 203)?
•  » » 15 months ago, # ^ |   +1 Atcoder TestCases DropBox LinkHere are all the test cases of Atcoder. ABC203 testcases will also be updated soon.
 » 15 months ago, # | ← Rev. 2 →   +14 When will the editorial be publish ? The Editorial page is still blank.
 » 15 months ago, # |   0 Can we do problem D using a sliding window? I tried using ordered_set but got TLE.
•  » » 15 months ago, # ^ |   0 Well, did you take care of the fact that ordered_sets only keeps the unique elements in ascending order? And if you did, could you share me a link to your submission? I found a link on GfG that takes care of that using Fenwick tree but turned out it was an incorrect implementation!
•  » » » 15 months ago, # ^ |   +1 To break ties you can compare indices, those are always unique
•  » » » 15 months ago, # ^ |   0 You can also use ordered multiset , I did that Time complexity was O(N^2 Log(N^2)) Not sure on complexity though .
•  » » » » 14 months ago, # ^ | ← Rev. 2 →   +3 Actually to be precise N = (n — k) from the problem. n x n grid and fitting k x k squares in we have (n — k) * (n — k) possible placements.And I think O(N^2 Log(N^2)) does not factor the transition cost. We're doing a rolling median across N^2 possible squares with transition cost N each time so an extra N factor and we get O(N^3 Log(N^2)).So worst case we have about 400 ^ 3 * (log 400^2) = 1280000000 ~ 1.3e9 operations. I think this takes about 10 seconds in a fast language
•  » » 15 months ago, # ^ |   0 I did thought of this but was unable to implement .I think if not binary search then it is clever sliding window as we have to delete and append k elements in our multiset also multiset will contain element in order that their count should be maximum.Then we can calculate median = (2*mean+mode)/3; where mode will be the first element in our multiset.
 » 14 months ago, # |   0 chokudai , math957963 , penguinman Hey, I just realised atcoder do not consider memory from global space allocation during calculation of memory used by submission, I solved E of this contest using global array and it didn't got counted towards memory used, and when I did same memory allocation in main it was counted, is it a bug or uniqueness of atcoder? because in this blog a user said generally in OJ all memory are counted towards the cost.