### chokudai's blog

By chokudai, 3 years ago,

We will hold AtCoder Beginner Contest 185.

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

We are looking forward to your participation!

• +60

| Write comment?
 » 3 years ago, # |   +6 5 min left to start !
 » 3 years ago, # | ← Rev. 3 →   -30 40 seconds left.....
 » 3 years ago, # |   +14 Am I the only one who felt C and F were too classical problems? :/
•  » » 3 years ago, # ^ |   0 no
•  » » » 3 years ago, # ^ | ← Rev. 2 →   +10 Then, I think they should not include these kind of problems because they are just basic.
•  » » » » 3 years ago, # ^ |   +9 Then, I think they should not include these kind of problems because they are just basic. Then you need to learn the basics.
•  » » » » » 3 years ago, # ^ | ← Rev. 2 →   0 I mean what's the point if they are only giving problems whose solutions are already known to people? (They don't even need to think) They are pretty standard problems.
•  » » » » » » 3 years ago, # ^ |   +5 I mean what's the point if they are only giving problems whose solutions are already known to people? They are pretty standard problems. Do you know all the solutions? If not then it is a good way to learn about the standard problems. It is already mentioned that this is a beginner contest and it is a great opportunity to apply those standard techniques. Then what is the problem?
•  » » » » » » » 3 years ago, # ^ | ← Rev. 2 →   0 I'm not talking about all problems but three of them are(C,E,F) and I understand that this is a beginner contest but does that mean that you will give questions which are one google search far from the solution? And if yes, then there is no point of giving such contest because one can practice that stuff at Leetcode, GFG etc. also.
•  » » » » » » » » 3 years ago, # ^ |   +2 E was a very good standard problem with a twist. Really a very good problem.C was good at its place. It needs basic DP or Combinatorics knowledge.You can say F was too standard and I also agree with that.
•  » » 3 years ago, # ^ |   0 Not sure of C but F was for sure
•  » » » 3 years ago, # ^ |   +14 C was a standard combinatorics problem
•  » » 3 years ago, # ^ |   0 E and F were also classical common problems !!
•  » » 3 years ago, # ^ |   +13 F was basically editing the merge function in my segment tree template
•  » » » 3 years ago, # ^ |   +4 Or maybe copying the exact same code from gfg ;_;
 » 3 years ago, # |   0 How solve F ??
•  » » 3 years ago, # ^ |   0 use segment tree with xor as merge operation of two segments.
•  » » 3 years ago, # ^ |   0 classic segment tree problem
•  » » 3 years ago, # ^ |   +23 You can use Fenwick tree for range based queries. It's standard for range sum.
•  » » 3 years ago, # ^ | ← Rev. 2 →   -9 Using binary indexed tree for each bit independently, you can check if the number of bits in the range from x to y are odd or not.Code
 » 3 years ago, # |   +1 How to do E?
•  » » 3 years ago, # ^ | ← Rev. 3 →   +11 Problem E can be solved using DP . Following is transition formula (based on if we want to pair index n with m or we want to discard index n or we want to discard index m) : transition dp[n][m] = min({solve(n-1,m-1)+((long long)(a[n]!=b[m])),solve(n,m-1)+1,solve(n-1,m)+1});where n is index of array a and m is index of array b . Base case is when n is equal to 0 or m is equal to 0 . If n=0 then we need to discard prefix of length m in array b .
•  » » 3 years ago, # ^ |   0 just calculate the edit distance between A and B.
•  » » 3 years ago, # ^ |   +11 It simply reduces to the classical Edit Distance problem. Try to prove it yourself.
•  » » 3 years ago, # ^ |   +8 I use dynamic programming for solving E. Starting from the left if both elements are equal then you don't need to do anything otherwise do one of the three: 1. remove element from first array. 2. remove element from second array. 3. don't remove any just count 1 as penalty for element being not equal. If reach at the end of any array remove remaining elements from the other array. ll solve(ll ar1[],ll ar2[],ll i,ll j,ll n,ll m) { if(i == n) { return m-j; } if(j == m) { return n-i; } if(dp[i][j] != -1ll) return dp[i][j]; if(ar1[i] == ar2[j]) { return dp[i][j] = solve(ar1,ar2,i+1,j+1,n,m); } return dp[i][j] = min({solve(ar1,ar2,i+1,j,n,m),solve(ar1,ar2,i,j+1,n,m),solve(ar1,ar2,i+1,j+1,n,m)}) + 1; }
•  » » » 3 years ago, # ^ |   0 Thanks for explanation !!
 » 3 years ago, # |   0 How to solve C ??I solved D but not C
•  » » 3 years ago, # ^ |   +4 nCr(n-1,11)
•  » » » 3 years ago, # ^ |   0 Used this formula, but passed only 10/ 16 Test Cases:/ Where am I going wrong? https://atcoder.jp/contests/abc185/submissions/18756020Appreciate the help.
•  » » » » 3 years ago, # ^ |   0 naturell Check this outll nCr(ll n , ll r) { if(n(n-r);k--) { ans *= k; if(p<=r) { ans/=p; p++; } } return ans;}
 » 3 years ago, # |   +4 Does anybody know how to solve the E question? I tried longest common subsequence approach but got WA.
 » 3 years ago, # |   +14 Here's an unofficial editorial .Problem A : Just take the min of given 4 values Problem B : Just take the difference of consecutive numbers and alternatively subtract and add. CodeProblem C : One of the simple solution is DP. Let dp(x,y) is number of ways to cut x, into y pieces then our required result is dp(l,12);The recurrence is dp(x,y) = dp(x-1,y) + dp(x-1,y-1); // you cut a piece of 1 from prefix or you don't cut The base cases if(x==y) dp(x,y) = 1; // all pieces of 1 if(x
•  » » 3 years ago, # ^ |   0 C is also l - 1 choose 11 because we have l - 1 choices and have to select 11.
•  » » 3 years ago, # ^ |   +14 Main problem in E is to get your head arround what the problem statement asks for.
•  » » 3 years ago, # ^ | ← Rev. 2 →   +3 it should be obvious to many, but if someone feel confused by, dp(x,y) = dp(x-1,y) + dp(x-1,y-1); you cut a piece of 1 from prefix or you don't cutread this, just ordered the expression as in text dp(x,y) = dp(x-1,y-1)+ dp(x-1,y) ; you cut a piece of 1 from prefix or you don't cut
 » 3 years ago, # |   0 somebody tell me how to solve B. as i m beginner .
•  » » 3 years ago, # ^ | ← Rev. 2 →   0 Just do what the problem says.
•  » » » 3 years ago, # ^ |   0 Just do what the problem says. ... and check after each step if c<=0.
•  » » » » 3 years ago, # ^ |   0 and see that capacity cannot be more than the maximum capacity
 » 3 years ago, # |   0 I solved A,B,D,E,F but was not able to solve C. Any hint would be appreciated.
•  » » 3 years ago, # ^ |   0 Combinatorics
•  » » » » 3 years ago, # ^ | ← Rev. 2 →   0
•  » » » » 3 years ago, # ^ |   0 There is a dynamic programming approach to find the values of $n \choose r$. The recursive formula is: $\binom{n}{r} = \binom{n-1}{r} + \binom{n-1}{r-1}$
•  » » » » » 3 years ago, # ^ |   0 can i get the code..please sir
•  » » » » » » 3 years ago, # ^ |   0 It's pretty common. Just google it :)
•  » » » » 3 years ago, # ^ |   0
•  » » » » 3 years ago, # ^ |   +8 Use __int128 — https://atcoder.jp/contests/abc185/submissions/18738450
•  » » » » 3 years ago, # ^ | ← Rev. 2 →   +3 One loop, No __int128: https://atcoder.jp/contests/abc185/submissions/18740485
•  » » 3 years ago, # ^ |   +1 You can use dp of 12*200 states where dp[i][j] means ith cut at jth position .submission
•  » » 3 years ago, # ^ |   0 it is just simple dp, you can either make a cut at the position you are at or not make a cut, when u have 11 cuts just check if it has made 12 valid cuts and there you go!
•  » » 3 years ago, # ^ |   0 You can type the star and bars formular from head or implement some more or less simple dp. I tried to google the formular but without success then implemented the dp.
•  » » 3 years ago, # ^ |   0 Number of ways to choose 11 from (L-1). Simple combinatorics.
•  » » 3 years ago, # ^ |   0 Basic combinatoric problem just be careful about overflows you need to divide numbers while you are able to have integer result when calculating nCr
•  » » 3 years ago, # ^ |   0 ans is l-1C11. We have total l-1 positions to place bar in which we have to choose only 11 of them.
•  » » 3 years ago, # ^ | ← Rev. 3 →   0 If there is a rod of length L, we have 0,1,2,3,....,N-1,N positions on rod. So in total we have (n+1) points, but we can't make a cut at the extreme ends, so we just have to choose 11 points from the remaining (n-1) points, so answer is simply (n-1)Cr .In order to avoid the overflow, I divided the numerator and denominator with their gcd in every iteration. Spoilerint ans = 1; int deno = 1; fo(i, 1, 11) deno *= i; rfo(i, n, n - 10) { ans *= i; int g = __gcd(ans, deno); ans /= g; deno /= g; }
•  » » 3 years ago, # ^ |   0 Infact I tried dp but my transitions were wrong
 » 3 years ago, # |   0 Can we solve problem F using SQRT decomposition? , although I solved using seg tree, still can we solve it?
•  » » 3 years ago, # ^ |   0 With segment tree it is O(nlogn), with SQRT aka Mo it is O(n sqrt(n)), which is more, but still could fit the timebox.
 » 3 years ago, # |   0 Can someone help find the mistake ?
•  » » 3 years ago, # ^ | ← Rev. 12 →   +5 is if(S<=s && E>=e)return tree[id]; not if(S>=s && E<=e)return tree[id]; here
 » 3 years ago, # |   +5 Approach to problem F: goto geeksforgeeks, copy the solution , edith for input and submit. Wooooow, you solve a problem with 600 point. Fuck.........
 » 3 years ago, # |   0 In problem B, the statement was not clear to me although I solved it after looking at the examples. It said that "Determine whether he can return home without the battery charge dropping to 0 on the way.", so it meant that we have to determine battery charge dropping to 0 when he was on his way home after visiting M cafes?
•  » » 3 years ago, # ^ |   0 There are two possible interpretions: Drop to 0 at any point of time, or in the end. So that is what the examples for, we have to interpret them if not sure.
 » 3 years ago, # |   0 How to solve E using LCS? My logic is given belowcommon_elements = lcs(arr, brr, n, m); [calculate number of common elements using LCS]y = min(n, m) — common_elements; [number of elements in the array which are not equal arr[i] != brr[i]]x = max(n, m) — min(n, m); [numbers you have to delete to keep the length of both arrays same]mySolution
•  » » 3 years ago, # ^ |   +3 For the test case : 5 5 1 0 9 2 4 1 2 8 7 4 According to the question, X would be 0 and Y would be 3. Your code would return 2 whereas the answer should be 3 or am I wrong in understanding this...?
 » 3 years ago, # |   0 I couldn't find the bug in my implementation of segment-tree for F. Please help. Code
•  » » 3 years ago, # ^ |   0 I think you have not read the question properly. For every 1 type query, you have to replace a[x-1] with a[x-1]^y, not with y
•  » » » 3 years ago, # ^ |   0 I did so inside my update function. Inside the else if block Where I updated the tree node as t[node]=combine(t[node],val);
•  » » » » 3 years ago, # ^ |   +1 finally found the bug. In update you have called left node both times.It should be right in second call
•  » » » » » 3 years ago, # ^ |   +1 thanks a lot brother.
 » 3 years ago, # | ← Rev. 2 →   +11 My solutions to this contest, along with detailed explanations of the solutions, can be found here :)
 » 3 years ago, # |   0 is there any way to get editorial of this contest as i am not able to solve 3 question and i want a editorial for it is there a way.
•  » » 3 years ago, # ^ |   +8 Check this.
 » 3 years ago, # |   +16 I have written an unofficial English editorial.you can find it here..
•  » » 3 years ago, # ^ |   +5 thnks bro
 » 3 years ago, # |   0 can someone explain segment tree in PF?
 » 3 years ago, # | ← Rev. 2 →   0 Can anybode see what is wrong with my code?My idea is to first swap the two array to make array $a$ has less or the same amount of numbers than array $b$. I observe that it is optimal to not deleting any number from array $a$, since if $|A'|<|A|$, we can add a number to the end of each of array $a$ and $b$ and $x$ will decrease by $2$ while $y$ will only increase by at most $1$. Then, I use DP, for which $dp[i][j]$ is the minimum value of $x+y$ when we only consider the first $i$ value of array $b$ and the first $j$ value of array $a$. The answer is $dp[m][n]$.
•  » » 3 years ago, # ^ | ← Rev. 2 →   +4 Check this test: 4 3 1 1 2 3 2 3 1 It's better to delete $A_1$, $A_2$ and $B_3$ with cost = 3. Your code prints 4.
•  » » » 3 years ago, # ^ |   +5 Got it. Thanks!
•  » » » 3 years ago, # ^ |   0 I also have a similar kind of problem. Could you please help.Code LinkI understood from your test case, that what I was doing wrong. But, can we not iterate over all the "subsequence sizes", and fix it ?
 » 3 years ago, # |   +9 Just my feedback I think this round was way easier than general. Actually the difficulty of all A-F in this round should actually be A-D, and E, F need to be a bit challenging, requiring more thinking for beginners to be challenged. D was also quite easier more like B. Thank you!
 » 3 years ago, # | ← Rev. 3 →   0 Can someone help me with this solution of D https://atcoder.jp/contests/abc185/submissions/18768487 ?
 » 3 years ago, # |   0 How to approach D problem? Help me, please!
•  » » 3 years ago, # ^ |   +8 The idea is that we want to use the biggest k possible, because then we need to use the stamp the minimum number of times.On the other hand, k must not be bigger than the smallest consecutive segments of blue cells, because if it is bigger, then we cannot use the stamp on that segment.So we choose k as the number of cells in the smallest such segment, and then count foreach segment how often we need to use the stamp.
•  » » » 3 years ago, # ^ |   +5 I got It. Thanks a lot, Mr. SpookyWooky ... God bless you!
 » 3 years ago, # |   +13
 » 3 years ago, # |   0 Would anyone be able to find the problem in my code for the segment tree in F? My implementationIt is being accepted on samples but failing in randomized tests. Thanks
•  » » 3 years ago, # ^ |   +3 You forgot to update arr after 1st type of operation. Just add arr[x-1] ^= y; after updateTree and you'll get AC.
•  » » » 3 years ago, # ^ |   0 Shouldn't I just be updating my segment tree array tree with the update query? It's being updated at - tree[ind] = val in one of the updateTree cases. Moreover, val ,that I passed was equal to arr[x-1]^y Shouldn't that be enough? Thanks for looking into it...
•  » » » » 3 years ago, # ^ |   0 Consider two update queries for the same index x. You pass arr[x-1]^y, but then never update arr[x-1], so in the next update query with this index, you will XOR with the initial value itself.
 » 3 years ago, # |   0 If anyone is interested, I streamed my virtual participation & explained the solutions after, you can find the upload here: https://youtu.be/PLIm4jYYaHk
 » 3 years ago, # | ← Rev. 3 →   0 Why can I post the editorial? Is it a bug or a feature?I was curious about the "post editorial" button and tried to write one, but it somehow appeared where the official editorial should be.Should I delete it?Upd: It seems that all users with a rating more than 2000 have the access.