### atcoder_official's blog

By atcoder_official, history, 4 weeks ago,

We will hold AtCoder Beginner Contest 350.

We are looking forward to your participation!

• +53

 » 4 weeks ago, # |   0 GLHF！
 » 4 weeks ago, # |   -30 Best point values i have ever seen!!!
•  » » 4 weeks ago, # ^ |   0 Why?
 » 4 weeks ago, # |   0 I'm late for it! So I had to registered by Unrated!
•  » » 4 weeks ago, # ^ |   -15 So sad:(
•  » » 4 weeks ago, # ^ |   0 sad(:
 » 4 weeks ago, # |   0 How to do D?
•  » » 4 weeks ago, # ^ |   0 Although I didn't solve D, I'm guessing it could be solved using a graph/tree data structure.
•  » » 4 weeks ago, # ^ |   0 by union-findlike this
•  » » » 4 weeks ago, # ^ |   0 Guessed it correctly then. Although I learnt DSU,couldn’t implement it.
•  » » 4 weeks ago, # ^ |   +1 a very easy approach other than DSU. first thing to observe is that in every connected component, every node will be friend to every other node. this leads us to the conclusion that every connected component should be a complete graph. in a complete graph, the number of edges is given as: $M = \frac{n(n - 1)} {2}$Now the problem is reduced to something very easy. For each connected component, find the number of nodes it has. this will gives us the required number of edges per connected component. After that you can either subtract m at the end or separately count the number of edges in every connected component and subtract it from the number of edges in a complete graph.My Submission: Link
•  » » » 4 weeks ago, # ^ |   0 I am subtracting m at the end as you said, but is giving Wrong Answer for some cases, if possible can you helpHere is my submission Link: https://atcoder.jp/contests/abc350/submissions/52650972
•  » » » » 4 weeks ago, # ^ |   0 you are reading N edges instead of Mthe faulty part:  for(int i=1;i<=n;i++) { int a,b; cin>>a>>b; g[a].push_back(b); g[b].push_back(a); } it should be  for(int i=1;i<=m;i++) { int a,b; cin>>a>>b; g[a].push_back(b); g[b].push_back(a); } hope it works.
•  » » » » » 4 weeks ago, # ^ |   0 Thanks a lot!!
•  » » 4 weeks ago, # ^ |   0 I checked evima editorial on yt, it was DFS
•  » » » 4 weeks ago, # ^ |   0 i do it with dsu as mentioned by the above user
•  » » » » 4 weeks ago, # ^ |   0 can you share your code link? I tried with Dsu but 15 testcase didnt passed
 » 4 weeks ago, # |   0 wtf this tasks
•  » » 4 weeks ago, # ^ |   -6 Exactly my thoughts. A-F is criminally bad. Idk about G.
•  » » » 4 weeks ago, # ^ |   0 What do you find bad about them ?
•  » » » » 4 weeks ago, # ^ |   0 They are trivial and way too standard. I only read G 5 mins ago and it's terrible as well, I can't spoil the solution rn but it's a standard optimization, I regret not reading it earlier.
•  » » » » » 4 weeks ago, # ^ | ← Rev. 2 →   0 Today, I gave my first atcoder contest and was able to solve 4. How many problems are you able to solve in those contests, generally ? And, how many did you solve today ?
•  » » » » » » 4 weeks ago, # ^ |   0 I know ideas to 6 on average, today all 7 (but didn't code G). I usually don't solve <5.
•  » » » » » » » 4 weeks ago, # ^ |   0 Thanks
•  » » » » 4 weeks ago, # ^ |   0 +1
 » 4 weeks ago, # |   +4 Loved E
 » 4 weeks ago, # |   0 E — Toward 0 Problem Statement: You are given an integer N. You can perform the following two types of operations:Pay X yen to replace N with ⌊ A N ⌋.Pay Y yen to roll a die (dice) that shows an integer between 1 and 6, inclusive, with equal probability. Let b be the outcome of the die, and replace N with ⌊ b N ⌋.i didnt understand this question much but the testcases made it worst :(
 » 4 weeks ago, # |   0 Is G just small to large merging?
•  » » 4 weeks ago, # ^ |   0 Yes. My solution is: For each node I calculated its parent and depth in its component(a tree). Also I used union find to check if two nodes are in the same component. Notice that you can answer each query using calculated values. To merge two nodes, I recalculated the depth and parent of every node in the smaller component out of the two.
•  » » » 4 weeks ago, # ^ |   0 Could you help me find out why this solution gives RTE, TLE and WA? It seems to be what you described.Submission Link
•  » » » » 4 weeks ago, # ^ |   0 By a close look I think you should update ancestors inside of dfs on all nodes.
•  » » » » » 4 weeks ago, # ^ |   0 I don't think so, I'm updating only the smaller child when merging.
•  » » » » » » 4 weeks ago, # ^ |   0 What I did in my solution is I updade all parents on smaller tree + all depths and when considering a query 2 u v I take the deeper node by depth let it be v and I check if parent[v] is adjacent to u. I use sets in adjacency list to make that quick.
•  » » 4 weeks ago, # ^ | ← Rev. 2 →   0 I remember who the parent is for every node + keep a DSU to tell which component is smaller for merging. When merging I update the parents in the smaller tree so that the node from current query becomes its root. The runtime is 24 ms though, so I'm not sure if it's even necessary to merge small to large here?up: Resubmitted with random swaps and got TLE, so small to large seems necessary.
•  » » 4 weeks ago, # ^ | ← Rev. 2 →   +3 sqrt also passed: split vertices to small an big by current deg. for small store all pairs of neighbours (will be $O(n \sqrt n)$ total) in set.
•  » » » 4 weeks ago, # ^ |   0 Thanks for the solution! Do you think the small memory limit was designed to kill sqrts, or for something else?
•  » » » » 4 weeks ago, # ^ |   0 I guess to kill bitsets
 » 4 weeks ago, # | ← Rev. 2 →   0 For question D, I tried to do it with DSU but failed 16 cases don't know why.My implementation was like:long long find_parent(ll u,vector&parent) { if(u == parent[u]) { return parent[u]; } return parent[u] = find_parent(parent[u],parent);}// For unionvoid union_set(ll u,ll v,ll parentU,ll parentV,vector&parent,vector&ranks,ll &ans) { ll ru = ranks[parentU]; ll rv = ranks[parentV]; if(ru
•  » » 4 weeks ago, # ^ |   0 i can't read your code, but there can be more than one connected component, which you may have missed.
•  » » » 4 weeks ago, # ^ |   0 I considered that case also, and I have updated my code now.That ans = ans + (ru-1)*rv + rv-1; is handling those cases in which when there are multiple components.like1 is connected with 2,3,4. So, 1's rank will be 4.6 is connected with 7,8. So, 6's rank will be 3.Now I want to connect 6 with 1. Now, this formula will do its job.
•  » » 4 weeks ago, # ^ |   0 I was not able to understand D. In the last sample test case it is showing 12 as answer. can someone please explain how 12? I am getting more than 12. If i make 1 and 3 as friend and 3 and 4 are already are friend then i can make 1 and 4 friend as well.
•  » » » 4 weeks ago, # ^ |   0 To understand this question, you need to know DSU's working when implemented with path compression and rank optimization.
•  » » » » 4 weeks ago, # ^ |   0 ok thanks. Let me check dsu.
•  » » » 4 weeks ago, # ^ | ← Rev. 2 →   0 Actually a simple dfs works:- For any connected component find the no of vertices(v) and edges(e) it has. Then the answer is simply incremented by (vC2-e) where vC2=(v*(v-1))/2 for each component.
•  » » 4 weeks ago, # ^ |   0 Your ideal is similar to mine, When there is a pair in so you have to subtract the answer which is 1. My code https://atcoder.jp/contests/abc350/submissions/52618619.
 » 4 weeks ago, # |   0 How to solve A and B for just 47 seconds? I could not even open the tasks for that time :)
•  » » 4 weeks ago, # ^ |   0 +1
 » 4 weeks ago, # |   +10 how to solve $E$?
•  » » 4 weeks ago, # ^ |   +1 Just DP/memoization, the only problem is with dice roll possibly giving you a 1, but that just multiplies the expected number of moves when choosing to roll a die by $\frac{6}{5}$.
•  » » » 4 weeks ago, # ^ |   0 I thought that this solution would get TLE so I didn't implement it.How can we prove that the states number is small enough?
•  » » » » 4 weeks ago, # ^ |   +1 As written in Japanese editorial, any state to consider can be expressed in a form $\lfloor N / (2^p 3^q 5^r) \rfloor$, where $p, q, r$ are non-negative integers, since $\lfloor \lfloor N / x \rfloor / y \rfloor = \lfloor N / xy \rfloor$. Each of $p, q, r$ have only $O(\log N)$ possibilities, so in total the number of states is $O(\log^3 N)$.
•  » » 4 weeks ago, # ^ | ← Rev. 3 →   +1 DP calculating cost to reach 0 from current number. Min of 2 ways:paying X yen for first wayX + f(num // A)paying Y yet to throw the dice(6 * Y + f(x // 2) + f(x // 3) + f(x // 4) + f(x // 5) + f(x // 6)) / 5You get this from f(x) = Y + (f(x // 1) + f(x // 2) + f(x // 3) + f(x // 4) + f(x // 5) + f(x // 6)) / 6To get rid of the infinite recursion, move all f(x)'s to the left
•  » » » 4 weeks ago, # ^ | ← Rev. 2 →   0 The last equation should be — f(x) = Y + (f(x // 1) + f(x // 2) + f(x // 3) + f(x // 4) + f(x // 5) + f(x // 6)) / 6 Instead of, f(x) = (Y + f(x // 1) + f(x // 2) + f(x // 3) + f(x // 4) + f(x // 5) + f(x // 6)) / 6 To arrive at the equation — f(x) = (6 * Y + f(x // 2) + f(x // 3) + f(x // 4) + f(x // 5) + f(x // 6)) / 5P.S. — You have put Y in bracket and divided by 6 in the last equation.
•  » » » » 4 weeks ago, # ^ |   0 can you please elaborate more ?
•  » » » » » 4 weeks ago, # ^ | ← Rev. 2 →   +3 Let F(x) be the cost of reducing x to 0. When rolling a dice, we will pay Y cost. The dice on rolling will give either — 1,2,3,4,5 or 6 If it is 1, the cost will be F(x) = Y+F(x/1) If it is 2, the cost will be F(x) = Y+F(x/2) If it is 3, the cost will be F(x) = Y+F(x/3) If it is 4, the cost will be F(x) = Y+F(x/5) If it is 5, the cost will be F(5) = Y+F(x/5) If it is 6, the cost will be F(x) = Y+F(x/6) But, we need to find expectation value of F(x), which is essentially the mean. Hence,F(x) = (6*Y+F(x/1)+F(x/2)+F(x/3)+F(x/4)+F(x/5)+F(x/6))/6 F(x) = Y+(F(x/1)+F(x/2)+F(x/3)+F(x/4)+F(x/5)+F(x/6))/6 Note, that there is a F(x) term on both LHS and RHS (This is because F(x/1)=F(x),as dividing x by 1, will give x) Move the F(x) in the RHS to the LHS side, we get — F(x)-F(x)/6 = Y+(F(x/2)+F(x/3)+F(x/4)+F(x/5)+F(x/6))/6 Thus, 5*F(x)/6 = Y+(F(x/2)+F(x/3)+F(x/4)+F(x/5)+F(x/6))/6 Hence, F(x) = (6*Y+F(x/2)+F(x/3)+F(x/4)+F(x/5)+F(x/6))/5 Now, this can be solved using Recursion+Memoization. My Submission
•  » » » » » » 4 weeks ago, # ^ |   0 thanks a lot man. I was really having hard time solving.
•  » » » » » » 4 weeks ago, # ^ | ← Rev. 2 →   0 Thank you, Even I'm doubtful initially about cancelling out $f(\left\lfloor \frac{N}{1}\right\rfloor)$ but later saw your comment and felt good that I'm on track.In the editorial, it was $f(N) = Y + \frac{1}{5} f(\left\lfloor \frac{N}{2} \right\rfloor) + \frac{1}{5} f(\left\lfloor \frac{N}{3} \right\rfloor) + \frac{1}{5} f(\left\lfloor \frac{N}{4}\right\rfloor ) + \frac{1}{5} f(\left\lfloor \frac{N}{5}\right\rfloor) + \frac{1}{5} f(\left\lfloor\frac{N}{6}\right\rfloor)$$f(N) = Y + \frac{1}{6} f(\left\lfloor \frac{N}{1} \right\rfloor) + \frac{1}{6} f(\left\lfloor \frac{N}{2} \right\rfloor) + \frac{1}{6} f(\left\lfloor \frac{N}{3}\right\rfloor ) + \frac{1}{6} f(\left\lfloor \frac{N}{4}\right\rfloor) + \frac{1}{6} f(\left\lfloor\frac{N}{5}\right\rfloor) + \frac{1}{6} f(\left\lfloor \frac{N}{6} \right \rfloor)$Although it appears recursive due to $f(N)$ appearing on the right side, by shifting to the left and multiplying the entire equation by $\frac{6}{5}$, we get:$f(N) = \frac{6}{5}Y + \frac{1}{5} f(\left\lfloor \frac{N}{2} \right\rfloor) + \frac{1}{5} f(\left\lfloor \frac{N}{3}\right\rfloor ) + \frac{1}{5} f(\left\lfloor \frac{N}{4}\right\rfloor) + \frac{1}{5} f(\left\lfloor\frac{N}{5}\right\rfloor) + \frac{1}{5} f(\left\lfloor \frac{N}{6} \right \rfloor)$Final Problem$f(N) = \min⁡\left(X + f\left(\left\lfloor\frac{N}{A}\right\rfloor\right), \frac{6}{5} Y + \frac{1}{5} f\left(\left\lfloor\frac{N}{2}\right\rfloor\right) + \frac{1}{5} f\left(\left\lfloor\frac{N}{3}\right\rfloor\right) + \frac{1}{5} f\left(\left\lfloor\frac{N}{4}\right\rfloor\right) + \frac{1}{5} f\left(\left\lfloor\frac{N}{5}\right\rfloor\right) +\frac{1}{5} f\left(\left\lfloor\frac{N}{6}\right\rfloor\right)\right)$
•  » » » 4 weeks ago, # ^ |   0 but what if die is always roll to 1? Problem seems kinda incorrect to me
•  » » » » 3 weeks ago, # ^ |   0 The probability of such an event is 0.
 » 4 weeks ago, # |   0 what is problem with my solution in D? Three test case give me RE N, M = list(map(int, input().split())) par = [i for i in range(N)] def find(i): if par[i] != i: par[i] = find(par[i]) return par[i] def union(i, j): parI, parJ = find(i), find(j) if parI!=parJ: par[parI] = parJ return for _ in range(M): a, b = list(map(int, input().split())) union(a-1, b-1) size = [0 for _ in range(N)] res = 0 seen = set() for i in range(N): pari = find(i) seen.add(pari) size[pari] +=1 res = 0 for parId in seen: res+= (size[parId]-1)*size[parId]//2 print(res-M) Thanks a lot
 » 4 weeks ago, # | ← Rev. 2 →   +19
•  » » 4 weeks ago, # ^ |   0 marvellous
•  » » » 4 weeks ago, # ^ |   0 wow many people think such shit tests preparation is ok?
 » 4 weeks ago, # |   +10 Since some people are not impressed with the problems, I'd like to counterbalance and say that I quite enjoyed this round. In particular I don't think the tasks being doable and their difficulty curve being smooth is a bad thing for a contest like this, what with it having 'Beginner' in the name and all. :)
 » 4 weeks ago, # |   +8 Solved Problem F by using __gnu_cxx::rope for performing the fast reverse operations (solution) in 1041 ms and Problem G in $O(N \times Q \times \log{(N)})$ with sorted vectors and binary search in them (solution) in 2764 ms.
 » 4 weeks ago, # |   0 Any help with why my code in problem G is wrong? Code
 » 4 weeks ago, # |   +1 Is it possible to get banned in Atcoder?
 » 4 weeks ago, # | ← Rev. 2 →   0 Can anyone tell me why this solution for problem F is giving rte?Edit: Got AC had some issue in my treap implementation.
•  » » 4 weeks ago, # ^ | ← Rev. 3 →   0 .
 » 4 weeks ago, # | ← Rev. 2 →   -15 Actually, the brute force solution to problem G is correct. For instance, in order to make the brute force solution run most slowly, we can use the following graph and query $2\ 1\ n$ every time:However, the maximum number of queries is $10^5$, so the best solution (to make the brute force solution run most slowly) is to use $50000$ queries to build the graph I mentioned, and use the remaining $50000$ to query $2\ 1\ n$. We can calculate that the brute force solution will run $50000\times 25000=1.25\times 10^9$ times at most $^{[1]}$. With a 3s time limit, brute force can pass easily.$^{[1]}$: If we use $n$ queries to build the graph, and use the remaining $100000-n$ to query $2\ 1\ n$, the brute force solution will run for $\dfrac{n}{2}\times (100000-n)$ times. Obviously, this is a quadratic function with a maximum value of $1.25\times 10^9$.
 » 4 weeks ago, # |   0 Why do my answer get TLE if I use bfs, but get AC if I use dfs on Problem G？ DFS dfs: https://atcoder.jp/contests/abc350/submissions/52624937 bfs: https://atcoder.jp/contests/abc350/submissions/52624751
 » 4 weeks ago, # |   0 Hello, I don't understand the solution for Atcoder : is it a small in large merge ?
 » 4 weeks ago, # |   0 How to solve F using a stack?
•  » » 4 weeks ago, # ^ |   -8 solve it as balanced parenthesis. Reverse the segments with treap or splay tree and for lower-upper cases use scaline to count no of times an index is affected if it's odd change the case.
•  » » » 4 weeks ago, # ^ |   +7 I'll just say that your solution is a complete overkill. No need for any of that. Just store all the opening/closing intervals and try to come up with a recursive function that prints the interval [l,r], provided s[l]=='(' and s[r]==')'. It works in O(N).
•  » » » » 4 weeks ago, # ^ |   0 I didn't get you, how will you reverse the respective segments without them??It's obvious that we takes intervals [l, r] with given conditions same as we do in balanced parenthesis with the help of stack.
•  » » » » » 4 weeks ago, # ^ |   +3 Here's a link to my submission. UrlThe trick is that you don't actually have to perform these operations. You just need to know the "depth" of a parentheses meaning the number of open parentheses that come before it that are not yet closed.The idea is very similar to the problem of reverals of word order in a string. For example "this is good" reversed os "good is this". This can be achieved by first reversing each word and then the whole string:"this is good" -> "siht si doog" -> "good is this"If you can find an efficient way to solve this problem in one pass each depth of parentheses define words of the new "sentence".Hope this helps. It's a bit hard to explain, but essentially you only care about whether you print the interval from left to right or right to left.
•  » » » » 4 weeks ago, # ^ | ← Rev. 3 →   0 My Recursive solution gives TLEstring toggleAndReverseString(string &res){ for(char &ch:res){ if(isupper(ch)){ ch = tolower(ch); } else{ ch = toupper(ch); } } reverse(res.begin(),res.end()); return res; } string helper(ll &idx,string &str,ll len){ // cout<<"idx = "<>str; ll idx = 0; ll len = str.length(); cout<>str; ll len = str.length(); vectorreversibleString(len); stackst; ll countofOpenBrackets = 0; for(ll i=0;i
 » 4 weeks ago, # |   +16 Will the testcases of A update after ABC350?
•  » » 4 weeks ago, # ^ |   0 no
•  » » 4 weeks ago, # ^ |   0 I think it should be that, but the fact is not......
 » 4 weeks ago, # |   0 can someone please explain the solution of F ?
 » 4 weeks ago, # | ← Rev. 2 →   0 Can someone please explain the solution for problem E ?
 » 4 weeks ago, # |   0 In problem G, the inputs seem to be generated randomly, how come they guarantee that for type 1 queries u, v belong to different connected components
 » 4 weeks ago, # |   0 For Sample 3 in C,I think it's OK to print22 31 2But why was it false in judge?(AC*2 & WA*1)
•  » » 4 weeks ago, # ^ |   0 Are you sure that you have no problem with the other two samples?
 » 4 weeks ago, # |   0 is there something wrong in C sample output3? after exchange 1&2 and then exchange 2&3 , 312 will be 231,so i think it may be wrong
 » 4 weeks ago, # |   0 I solved ABCD,I am very weak...
 » 4 weeks ago, # |   0 Problem E Why can't use this?  std::array res{}; for (int b = 2; b <= 6; ++b) { res[b] = f(nn / b); } auto res2 = (y * 6 + std::accumulate(res.begin() + 2, res.end(), 0.L)) / 5.L; But this can pass.  std::array res{}; for (int b = 2; b <= 6; ++b) { res[b] = f(nn / b); } auto res2 = y * 1.2L + std::accumulate(res.begin() + 2, res.end(), 0.L) / 5.L; And why can this pass?  auto res2 = y * 1.2L; for (int b = 2; b <= 6; ++b) { res2 += f(nn / b) / 5.L; } `