### chokudai's blog

By chokudai, history, 5 months ago,

We will hold AtCoder Beginner Contest 165.

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

We are looking forward to your participation!

UPD:

In Problem E, the constraints says N <= 100000, but it turned out that the inputs are made under the condition N <= 200000.

It was revealed that only 6 people were affected by the defect of the problem E constraint, and 4 among them were rated competitors. As the impact is very minor, contestants excluding the four are going be rated, and the affected four will also be rated after rejudging to get AC on their submissions.

• +97

 » 5 months ago, # |   +35 2 ABC this weekend, what a time to be alive! Thanks a lot AtCoder team for making this quarantine more fun!
•  » » 5 months ago, # ^ |   +8 I guess extra contests are to cover up for the unrated ones
 » 5 months ago, # |   +11 Did the start time just got extended by 5 minutes?
•  » » 5 months ago, # ^ |   +11 Yep
•  » » 5 months ago, # ^ |   0 5 more minutes! extended by 10 now... Seems like they're having some issues.
•  » » » 5 months ago, # ^ |   -43 as always !
 » 5 months ago, # |   +1 website crashed ?
•  » » 5 months ago, # ^ |   0 Delayed by 10 minutes.
•  » » 5 months ago, # ^ |   0 I am getting signed out repeatedly
 » 5 months ago, # |   +5 RIP
 » 5 months ago, # |   +8 Site down?
 » 5 months ago, # |   +7 Again 502 Bad Gateway :(
•  » » 5 months ago, # ^ |   0 It's up now
 » 5 months ago, # |   +1 504 Gateway Time-out:(
 » 5 months ago, # |   0 Postponed for 5 minutes.
•  » » 5 months ago, # ^ |   +2 Now ten minutes.
 » 5 months ago, # |   0 Start time extended by 10 minutes.
•  » » 5 months ago, # ^ |   +1 Its good that they acted quickly otherwise this contest also could be unrated :D
 » 5 months ago, # |   0 Looks like the start time is extended by 10 minutes.
 » 5 months ago, # | ← Rev. 2 →   0 extended by more 5 min :(
•  » » 5 months ago, # ^ |   0 10 mins.
 » 5 months ago, # |   0 website is loading too slow
 » 5 months ago, # |   0 Will they just postpone the contest by increments of 5 minutes until enough people go away and there is less load on their servers??
 » 5 months ago, # |   -9 delayed due to inadequacy in problem
 » 5 months ago, # |   0 “The start will be delayed for 10 minutes due to an inadequacy discovered in the problem. I'm sorry.“
 » 5 months ago, # |   0 Here we go
 » 5 months ago, # |   -6 C is too hard for C, imo.
•  » » 5 months ago, # ^ |   0 easy
•  » » » 5 months ago, # ^ |   +1 yeah, for me it was hard :(
•  » » 5 months ago, # ^ |   0 Same for me. That C was insane :(.
•  » » 5 months ago, # ^ |   +8 Solved E, but didn't C...
•  » » » 5 months ago, # ^ |   0 I solved C but couldn't solve E :(
•  » » » 5 months ago, # ^ |   0 10! algorithm would worktake a look at the constraints
•  » » » » 5 months ago, # ^ | ← Rev. 3 →   +7 it would be (n+m-1)C(m-1), so worst case 19C10
•  » » » » » 5 months ago, # ^ |   +3 How could you get this formula?I saw same question in one educational round but i don't know proof behind this formula?
•  » » » » » » 5 months ago, # ^ | ← Rev. 2 →   0 there's a n*m size rectangle, at the beginning, you are at the bottom-left corner, now that formula is the number of ways to get to the right side of the rectangle only go right or top.
•  » » » » » » 5 months ago, # ^ | ← Rev. 2 →   +7 You have M distinct numbers you can give each number some frequency and frequency of each number can be between [0, N] (N = length of sequence), since you have to make sequence increasing so for any fix combination of numbers and frequencies there will be only one increasing sequence. So now the problem is reduced to find the number of solutions of equation f1+f2+f3+..+fm = N, where fi is frequency of ith number in the sequence.
•  » » » » » » » 5 months ago, # ^ | ← Rev. 5 →   0 total sequences are 92378 in worst case. C(19,10)=92378
•  » » » 5 months ago, # ^ |   0 Solved F but not C and E.
•  » » » » 5 months ago, # ^ |   +10 same. F was easy, if you know O(nlogn) solution for finding LIS.
•  » » » » » 5 months ago, # ^ |   0 Well actually I was doing LIS in O(nlogn) and I got TLE on 6 tests :C
•  » » » » 5 months ago, # ^ |   0 I tried solving F using coordinate compression and range-max segment tree. But i kept getting WA :( . Been trying to figure out the error, but I wasn't able to. Here is my submission WA solution
•  » » » » » 5 months ago, # ^ |   0 It also happened to me. lets denote some variable: max_val=maximum compressed valueprev_val=query(pos[u],pos[u])[value of the index of pos[u] , before line 45]1) in line 45: update(pos[u], val) -> update(pos[u],max(val,prev_val))2) in line 46:ans[u] = val -> ans[u] = query(0,max_val)3) in line 52:update(pos[u], 0) -> update(pos[u],prev_val)I suppose this works fine...
•  » » » » » » 5 months ago, # ^ |   +11 Thanks a lot. Realized that for considering the LIS for a path from 1 to k, I take the answer as dp(k), instead of max(dp(i)) for i from 1 to k.
•  » » 5 months ago, # ^ |   0 +1. Solved rest but couldnt do this.
•  » » 5 months ago, # ^ |   0 It was too hard for me too. I thought number of combinations will be too large. But turns out there can be at max 92378 for n=10 and m=10. So brute force works.
 » 5 months ago, # |   +3 How to solve C !
•  » » 5 months ago, # ^ |   0 just try all the state.
•  » » » 5 months ago, # ^ |   +6 Though I doubted whether it will get TLE in the beginning...
•  » » » 5 months ago, # ^ |   0 How does this work, I came to the conclusion that there are $10^{10}/2$ possible arrays to check. To much.
•  » » » » 5 months ago, # ^ |   0 No you are wrong ,There are much fewer arrays!! You can write a dfs to count them.
•  » » » » 5 months ago, # ^ |   0 There are 92378 possible arrays for N = 10, M = 10 that have A[i]>=A[i-1] only.
•  » » » » » 5 months ago, # ^ |   +1 Well, thanks for explanation.
•  » » » » » 5 months ago, # ^ |   0 how did you got this ?
•  » » » » » » 5 months ago, # ^ |   0 Either go with a brute solution and find using code or use P&C and we can say sum of gaps between consecutive numbers is at max m-1 and number of gaps are n-1, so g1+g2+g3... gn-1 + k = m-1, so number of whole number solutions of this equation are m-1+n-1Cn-1
•  » » » » 5 months ago, # ^ |   0 actually the number of array is 10 choose 10 with repetition so that means it is 19 choose 10 which is equal to 92378. I have solved it in the most crazy way. my submission
•  » » » » » 5 months ago, # ^ |   0 I did'nt get it... how is it becoming 19C10?
•  » » » » » » 5 months ago, # ^ |   0 It is a well known concept called combination with replacement. Imagine you have a pool of numbers from $1 - 10$, and you want to select $10$ numbers with replacement (ex you can take the same number multiple times) this can be found using $n+k-1 \choose k$. If you want to read more about [here](https://en.m.wikipedia.org/wiki/Stars_and_bars_(combinatorics))
•  » » » » » » » 5 months ago, # ^ |   0 Correction: it is $n + k - 1 \choose n$ which equal to $n + k - 1 \choose k - 1$
•  » » » » » 5 months ago, # ^ |   0 262 line code! really u r a coder.
•  » » » » 5 months ago, # ^ |   0 we should only consider monotonically increasing sequence
•  » » » » 5 months ago, # ^ |   +26 Combinatorial way to look at it.You need to find number of arrays $A = \{ A_1, A_2, ..., A_N \}$, such that $1 \le A_1 \le A_2 \le ... \le A_N \le M$.Let $x_i$ be the number of occurences of $i$ in the array. Then we require number of solutions to $x_1 + x_2 + ... + x_M = N$, where $x_i \ge 0$.This, given by Stars and Bars, is simply ${N+M-1} \choose {M-1}$ = ${10+10-1} \choose {10-1}$ = $19 \choose 9$ = $92378$.I usually use this website to do quick calculations for combinations, during contests.
•  » » » 5 months ago, # ^ | ← Rev. 2 →   0 :)
•  » » 5 months ago, # ^ |   0 Backtracking
•  » » » 5 months ago, # ^ |   0 would you plese explain!
•  » » » » 5 months ago, # ^ | ← Rev. 2 →   +3 Look at my code you'll get it: https://atcoder.jp/contests/abc165/submissions/12619964basically we generated all possible arrays.
•  » » 5 months ago, # ^ |   0 justint k = v[cur — 1]; while (k<= m) { v.push_back(k); dfs(cur + 1); v.erase(v.begin() + cur); ++k; }
•  » » 5 months ago, # ^ |   0 You can write a recursive brute force, which will include all possible states we can go to.Consider we want to fill n places. We start from place_id = 1, and num = 1.Now we have 3 possible cases: Don't include the current number at this place, so increment the 'num' by +1. Include the number so now we need to fill next place, so increment 'place_id' by +1 and continue using the same number for further positions. Include the number at the current position, but we don't want to use the same number for next pos, so increment both 'place_id' and 'num' by +1. If you are confused, you can take a look at my submission, though it isn't the cleanest. SubmissionI hope it helped.
 » 5 months ago, # |   -11 Honestly, I think it is not very wise to give such C and D in abc contest. I am sure there a thousends(?) of possible participants not submitting any solution because scared by a hard C and a D full of corner cases.Dont get me wrong, I think these are nice problems, but simply misplaced.
•  » » 5 months ago, # ^ |   +3 I can solve D by math with no corner cases. https://atcoder.jp/contests/abc165/submissions/12609383 Can not solve C. E. F.
•  » » » 5 months ago, # ^ |   +2 D was just to take x as min(b-1,n).
•  » » » 5 months ago, # ^ | ← Rev. 2 →   +5 F was easy with segment tree i think
•  » » » » 5 months ago, # ^ |   0 Are you serious ?Why you used segment tree for E?
•  » » » » » 5 months ago, # ^ |   0 sorry my bad, F
•  » » » » » » 5 months ago, # ^ | ← Rev. 2 →   +6 I think F by set will be more easy check thatvector < int > v[200005];int a[200005],ans[200005];bool vis[200005];set < int > s;void dfs (int r ){ vis[r]=true; int cc=-1,ff=-1; set::iterator it; if (s.insert(a[r]).second) { it= s.find(a[r]); it++; if (it!=s.end()) { ff=*it; s.erase(it); } cc=a[r]; } ans[r]=sz(s); for(auto i : v[r]) if(!vis[i]) { dfs(i); } if(cc!=-1) { s.erase(s.find(cc)); if(ff!=-1) s.insert(ff); }}
•  » » » 5 months ago, # ^ |   0 Would you please simulate your math formula!
•  » » » » 5 months ago, # ^ |   0 Take x as min(b-1,n)The second part of the function becomes zero and the first part becomes maximum.
•  » » » » 5 months ago, # ^ |   +6 you need to maximize, but if you observe for any x >= b, float[x/b] will always be greater than 0, and then you multiply it with A, but float[Ax/b] can atmost be equal to that. Thus its always optimal to make float[x/b] = 0, so that you answer is float[Ax/b]. To make that equal to 0, just take max x < b, but since x <= N, x = min(n, b-1). Then return the answer.
•  » » » 5 months ago, # ^ |   0 can you explain your solution please?
•  » » » 5 months ago, # ^ |   0 Explanation for D; If x increased by B, value not change, so we only consider x in range 0 — min(b-1,n); So The second part of the function becomes zero and the first part becomes maximum.
•  » » 5 months ago, # ^ |   0 Is C very hard?just try all the state!
•  » » » 5 months ago, # ^ |   0 I thought about that, just can not believe it will not get TLE. Maybe I evaluate time complexity wrong.
•  » » » » 5 months ago, # ^ |   +3 Why not write a simple dfs to count the number of them?
•  » » » » » 5 months ago, # ^ |   0 I calculated Combination(20, 10), and ... What the fxxx was I thinking about!!!
•  » » » » » » 5 months ago, # ^ |   0 Is it $C_{m+n-1}^n$ ?
•  » » » » » » » 5 months ago, # ^ |   0 Yes, you are right. I do not know how to input formula.
 » 5 months ago, # |   0 The English Commentary for Problem C and D is here
•  » » 5 months ago, # ^ | ← Rev. 2 →   +5 D with binary search... Wait. what? How? What does your check function do? The function isn't strictly increasing nor decreasing as far as I understand..
•  » » » 5 months ago, # ^ |   0 it's not increasing nor decreasing... however if you notice function is increasing in intervals of b. eg. from x = 0,1,2,..b — 1 f(x) is increasing at x = b f(x) again drops and starts increasing same as for previous x
•  » » » » 5 months ago, # ^ |   0 Exactly, since it drops at B, you can't binary search on interval (0,n). If you are Bsearching on interval (0,B-1), that isn't required, since it is increasing from 0 to B-1...so B-1 is going to give you maximum.Also, I am not sure if this Bsearch on (O,N) will work always. Since it is repeating maybe that is why it worked.
•  » » 5 months ago, # ^ | ← Rev. 2 →   0 Please provide proof of your construction in D
•  » » » 5 months ago, # ^ |   +2 The best idea is to use min(b-1,n). Simple and cute!
 » 5 months ago, # |   0 Can someone give a hint on E and F?
•  » » 5 months ago, # ^ | ← Rev. 2 →   +3 For F, Use Cute LIS :P to find lis for every node in dfs. My Submission.
 » 5 months ago, # |   0 Why is my ternary search failing on one test case for D? :((https://atcoder.jp/contests/abc165/submissions/12647186
•  » » 5 months ago, # ^ |   0 Why you are using ternary search ... Its just simple math
•  » » » 5 months ago, # ^ | ← Rev. 2 →   0 FI just assumed the function was unimodal and tried ternary search and it almost AC'd. Can you elaborate your solution?EDIT: unimodal not monotonic
•  » » » » 5 months ago, # ^ |   0 The function is repeating after every B values of X.Try to express X = qB + r and solve the equation. You will find that, function is max when r = (B-1). Also, in case, b — 1 > N, then N is your answer cause, from 0 to B-1 the answer is increasing.
•  » » » » » 5 months ago, # ^ |   0 when did you meet mike mirzayanov?
•  » » 5 months ago, # ^ |   0 @chosun Notice that if n>b no binary search or ternary search if you apply binary search from 1 to n. Binary search's lower and higher bounds will be [1, min(n, b)]
•  » » » 5 months ago, # ^ |   0 It works now thanks. Damn I was pulling my hair out last 5 minutes trying to debug this thing!
•  » » » » 5 months ago, # ^ |   0 This simple mistake cost 4 wrong submissions to me :(
•  » » 5 months ago, # ^ | ← Rev. 2 →   0 No need for ternary search, answer is monotonic with modulo value with B.
•  » » » 5 months ago, # ^ |   +1 When you know it is monotonic between 0 to B-1, when not just return B-1...
•  » » 5 months ago, # ^ | ← Rev. 2 →   0 or binary search My submission
 » 5 months ago, # |   0 Anyone tell how to do C
•  » » 5 months ago, # ^ |   0 C is just backtracking. Try all possibilities of the sequence
 » 5 months ago, # |   0 Problem statement of C was so confusing.Can anyone explain it?
•  » » 5 months ago, # ^ |   0 Please look at English Commentary of problem C here Thank you! Hope that helps!
•  » » 5 months ago, # ^ | ← Rev. 2 →   0 You are asked to create an array a, of size N. You should place values in that array from 1 up to M. The array should be not decreasing.Then you get those quadrupels. If you put at position a and b values, so that the difference is c, you get d points.Try to find an array with maximum possible points.
 » 5 months ago, # |   0 Im soooo stupid.
 » 5 months ago, # |   0 How to solve F ?
•  » » 5 months ago, # ^ |   0 Apply the O(nlogn) algorithm for LIS during the dfs while nullifying the changes made by a particular branch of a node when we visit its another branch.
•  » » 5 months ago, # ^ |   0 I maintained a segment tree for current root to node path for lis, and as i move down i make updates like in normal lis, and as i move up, i roll-back on the changes i did previously.
•  » » » 5 months ago, # ^ |   0 With segment trees and coordinate compression was required I think to backtrack.
 » 5 months ago, # |   +26 All the people complaining about C being too hard. Is it possible that they didn't notice the constraints that array is in increasing order A[1] <= A[2] <= A[3]..... <= A[N]? Because I skipped it initially and thought for several minutes that total case are $10^{10}$ which was outside the time limit.
•  » » 5 months ago, # ^ | ← Rev. 2 →   0 Same happened with me. How many possible combinations are possible ?a1 <= a2 <= ... <= an , (1<=ai<=m)Solved it, but I couldn't prove the time complexity.
•  » » » 5 months ago, # ^ |   +21 Observe, that if you pick set of numbers, there can be only one possible array, so you just need to count number to choose n elements from 1 to m, it is exactly $\binom{n+m-1}{n}\le 92378$
•  » » » » 5 months ago, # ^ |   0 There is a small mistake. I think the time complexity should be $C_{n+m-1}^{m-1}$.
•  » » » » » 5 months ago, # ^ |   0 It's actually the same because $\binom{n}{k}=\binom{n}{n-k}$
•  » » » » » » 5 months ago, # ^ |   0 I'm sorry. It's my mistake. I didn’t think twice. So stupid.
•  » » 5 months ago, # ^ |   -10 And... is 10^10 not outside the time limit?
•  » » 5 months ago, # ^ |   0 First i wrote a dp solution to count how many such arrays exists. Then used brute force. Spoiler#include using namespace std; int dp[11][11]; int go(int id, int last) { if (id == 10) return 1; if (~dp[id][last]) { return dp[id][last]; } int ans = 0; for (int i = last; i <= 10; ++i) { ans += go(id + 1, i); } return dp[id][last] = ans; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); memset(dp, -1,sizeof dp); cout << go(0, 1); return 0; } 
•  » » 5 months ago, # ^ |   +1 In fact there are only $C_{m+n-1}^n$
 » 5 months ago, # |   0 how to implement problem B ?? can anyone post their accepted solution
•  » » 5 months ago, # ^ |   0
•  » » 5 months ago, # ^ |   0 Brute Forces worked fine in given time limit. https://atcoder.jp/contests/abc165/submissions/12598199
•  » » 5 months ago, # ^ |   0
 » 5 months ago, # |   +39 Solns/Approaches A. Check every element B. Observe that answer never exceeds 5000 (use log to check). We can loop until success. C. Generate every possible combination. In python, we have combinations_with_replacement which generates exactly what we need D. Observe that for $x < b$, $\lfloor x/b \rfloor$ is zero. We want to take $x = kb-1$. Also observe that taking $k > 1$ always make the answer worst. We take $x$ as $\min(n, b-1)$. E. What we need is set of $(a, b)$s such that distance between $a, b$ never occurs twice. (Considering not only b-a, but we have to consider the other way. e.g, when $n = 10$, distance between $1$ and $10$ is 1 and 9. both should not appear again.)When $n$ is odd, take $(1, n), (2, n-1), \dots$. One can easily show that this is valid.When $n$ is even, take those values until we can't. (e.g, when $n = 10$, we take $(1, 10)$, $(2, 9)$ but not $(3, 8)$ since distance between $(3, 8)$ is 5 and 5 — repeated.) Then, discard one unused value and proceed. (e.g, after two takes, use $(3, 7)$ instead of $(3, 8)$, and $(4, 6)$.Submission : https://atcoder.jp/contests/abc165/submissions/12617571 F. Consider computing LIS length in $O(n \log n)$ time with DP and lower_bound. (without considering the actual values). When we do this, we discard what was in that spot (lower bound). Instead of doing this, keep those values by multiset or stuff like that. We traverse tree in DFS order, pushing values we meet in LIS-solving pattern but keeping values instead of throwing away. When we traversed all of it's subtrees, we erase value of the node from where we pushed. To do this we track the number of non-empty multisets and index we pushed each value in. Time complexity $O(n \log n)$.Submission : https://atcoder.jp/contests/abc165/submissions/12637543
•  » » 5 months ago, # ^ |   0 @gratus907 can you please tell how you came to conclusion for problem E?
•  » » » 5 months ago, # ^ |   0 I thought it intuitively after some casework... and I tried to prove my thought (I mean, not rigorously, but like convincing enough to start writing code)As I've wrote, a case when two people meet twice is only when there exists $(a, b)$ and $(c, d)$ which $b-a$, $n+a-b$, $d-c$, $n+c-d$ has repetitions. Try some casework in $n = 8$, $n = 10$ to convince yourself with this statement :) I actually have nothing much to say as I did tons of caseworks on paper...:(
•  » » » » 5 months ago, # ^ |   0 Thanks.
•  » » 5 months ago, # ^ | ← Rev. 2 →   0 You don't really need any multiset for problem F. Just change the value at lower_bound and remember what it was. After solving all subtrees and updating the answer just return the value to what it was. Submission
•  » » » 5 months ago, # ^ | ← Rev. 2 →   0 Apparently yes.. I discussed this problem with my friend after the contest and he also said the same thing. I felt very dumb since he coded like 800 bytes while I coded more than 2000... lolI have no idea how I managed to think returning values by dfs tree and then thought something like "WOW I want vector>" and started coding :(
 » 5 months ago, # |   0 How to solve D?
•  » » 5 months ago, # ^ |   0 take x as min(b-1,n)
•  » » 5 months ago, # ^ |   0 The target is to keep the minus part as small as possible.So tried to make the second part 0. So if n>=b, made it x=b-1 and it worked fine.
 » 5 months ago, # |   0 The Editorial is in Japanese. I want an English editorial.
•  » » 5 months ago, # ^ |   0 Generally they used to post english editorial after 5-6 days,but if you want you can google translate the pdf.(After translation it will have weird english but understandable)
 » 5 months ago, # |   0 I'm assuming some greedy strategy works for C. Can somebody please post their logic/solution? I filtered queries such that for each (a, b) indices pair — the optimal c for maximum d is known. For the array A[n], I set A[0] = 1. From here, I am confused about how to construct the rest of the array. I tried a couple of ways but there were always some cases not adhering to the rule.
•  » » 5 months ago, # ^ |   +1 C was a pruned brute solution i think.
•  » » » 5 months ago, # ^ |   0 Yeah. During the contest, I thought the time complexity would be too much. I wish I had checked it with a program though. For n = m = 10, there are about 48,000 possible sequences only.
•  » » 5 months ago, # ^ |   0 Spoilerimport java.util.*; import java.io.*; class Main { static int min; static int count(int[] a, int[][] queries) { int ans = 0; for(int[] q: queries) { if(a[q[1]]-a[q[0]]==q[2]) ans+=q[3]; } return ans; } static void recurse(int[] a, int idx, int prev, int m, int[][] queries) { if(idx==a.length) { min = Math.max(min, count(a, queries)); return; } for(int i = prev; i<=m; i++) { a[idx] = i; recurse(a, idx+1, i, m, queries); } } public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int q = sc.nextInt(); int[][] queries = new int[q][]; for(int i = 0; i
 » 5 months ago, # |   0 It seems difficult orz
 » 5 months ago, # |   +43 I think E is harder than F, as I'm not good at construction and pattern observing
•  » » 5 months ago, # ^ |   0 F was like if you know segment tree you will solve it immediately. Nothing special was in it
•  » » » 5 months ago, # ^ |   +19 How is segment tree related to F? I think most contestants solve it like this: submission
•  » » » » 5 months ago, # ^ |   +1 You can find lenghh of LIS ending at a node u, using segment tree as well after compressing a[i] s
•  » » » » » 5 months ago, # ^ |   +28 Oh, I got it. But I think this implementation is much easier.
•  » » » 5 months ago, # ^ |   0 Could you please Explain, how to solve F using segment tree. Thanks It_Wasnt_Me
 » 5 months ago, # |   +12 Is this round a bit easier than before? I used to solve 4 or 5 problems but today I solved 6 within a short time. Well anyway the problems are still very good (like, you can solve D and E with about 300 bytes of code but you need to think a long while). BTW, I think C is a bit hard for C. Since DFS may be not very "beginner-friendly".
 » 5 months ago, # |   +4 D one was way too easier than the C one
 » 5 months ago, # | ← Rev. 2 →   +5 Check Same question ... I still missed it.. hard luck today.
 » 5 months ago, # |   0 F is an easier version of NA Southeast Regional 2019 problem G
•  » » 5 months ago, # ^ |   0 Here it is on Kattis: https://open.kattis.com/problems/neverjumpdown
 » 5 months ago, # |   0 谁知道结果什么时候出来啊（When rating changes?）（I can't speak English well……）
 » 5 months ago, # | ← Rev. 4 →   -29 Nice contest!
•  » » 5 months ago, # ^ |   +12 This comment shouldn't be answered. This is a problem from an ongoing contest, Bubblecup.
 » 5 months ago, # | ← Rev. 2 →   +8 From stars and bars trick we get for C only 92378 states are there i.e ncr(10+10-1,10-1)
 » 5 months ago, # |   +4 A. Oh, constraints are really small, let's just iterate. B. Hm, it's exponential growth, I think max answer is not too big. Let's write and see (turns out max answer was in samples, but I didn't notice). C. Hm, seems like a lot of states, no idea, let's read D. D. Hmm, let's write bruteforce and see. Oh, it's always zero for multiples, ok, let's take multiple-1 if we can. C. Hmm, maybe there are not too many states? Let's write bruteforce and see. Oh, it's really small, dumb me. (It's just C(n + m — 1, n)) E and F are nice, but quite easy.
•  » » 5 months ago, # ^ |   0 How do you arrive at C(n + m — 1, n)? I had to count them by writing the dfs.
•  » » » 5 months ago, # ^ |   0
•  » » » 5 months ago, # ^ | ← Rev. 2 →   0 The sum of gaps between consecutive numbers is less than equal to m-1, it's basic P&C afterwards.
•  » » » 5 months ago, # ^ | ← Rev. 2 →   0 Watch this: https://youtu.be/XcmHB8nrlJE?t=722
•  » » » 5 months ago, # ^ | ← Rev. 3 →   +24 This is a classic stars and bars application. Note the condition that $1 \leq A_1 \leq A_2 \leq ... \leq A_n \leq M$. Thus, it is sufficient to count how many times each number from $1$ to $M$ appears in the sequence (because we would then only have one way to arrange these numbers---in nondecreasing order). So, now imagine a line with $N$ stars and $M-1$ bars. The stars before the 1st bar corresponds to the number of 1s, the stars between the 1st and 2nd bar correspond to the number of 2s, etc. For example, if m=4 and n=7, then *||****|** corresponds to one $1$, zero $2$s, four $3$s, and two $4$s. So, how many possible ways are there to arrange $M-1$ bars and $N$ stars in a line? There are $M+N-1$ "spaces", and of them we need to choose $N$ locations to be where we place the stars. We place the bars in all other locations.
•  » » » » 5 months ago, # ^ |   +5 Thanks!
•  » » » » 5 months ago, # ^ |   0 Isn't it "N locations to be where we place the stars. We place the bars in all other places"?
•  » » » » » 4 months ago, # ^ |   0 You are correct, I have edited it now. Thanks
 » 5 months ago, # |   0 Can someone explain the observation made in problem E.
•  » » 5 months ago, # ^ |   +1 check thiscould be helpful but a bit long explanation
•  » » » 4 months ago, # ^ |   +1 Thanks.. Quite good explanation
 » 5 months ago, # |   0 in problem E: if i match 1 with n then 2 with n-1 and so on (m times) why is it wrongI got WA with this approach in 9 test cases
•  » » 5 months ago, # ^ |   0 For 8 3, you would match 1 8 2 7 3 6 Consider, initially, $A = 1$, $B = 3$. They will fight at rounds 3($A = 3$ and $B = 6$) and 7($A = 7$ and $B = 2$).This strategy works for odd N though.
•  » » » 5 months ago, # ^ | ← Rev. 2 →   0 But this only happens when they have the same distance between the pairs. So if you avoid that special case, should it be right? https://atcoder.jp/contests/abc165/submissions/12657318
•  » » » » 5 months ago, # ^ |   +3 For 8 3 your code prints exactly the same output of my previous message.
•  » » » 5 months ago, # ^ |   0 initially,B = 4
•  » » » 2 months ago, # ^ |   0 In your reply,B=4
 » 5 months ago, # |   0 Can anyone prove the running time complexity for the brute solution of C please?
•  » » 5 months ago, # ^ | ← Rev. 2 →   0 O(Q * 92378) because number of valid(non-decreasing arrays) arrays with n = 10 and m = 10 are 92378. You can calculate this with dp or with Combinatorics. Code for Counting with Dp#include using namespace std; int dp[11][11]; int go(int id, int last) { if (id == 10) return 1; if (~dp[id][last]) { return dp[id][last]; } int ans = 0; for (int i = last; i <= 10; ++i) { ans += go(id + 1, i); } return dp[id][last] = ans; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); memset(dp, -1,sizeof dp); cout << go(0, 1); return 0; } 
 » 5 months ago, # |   0 Auto comment: topic has been updated by chokudai (previous revision, new revision, compare).
 » 5 months ago, # | ← Rev. 2 →   0 May someone help me debug F: LIS on Tree? I have done using binary search and dynamic programming. I have used 0-indexed dp. My submission: https://atcoder.jp/contests/abc165/submissions/12674946
•  » » 5 months ago, # ^ |   +5 test3 2 3 1 1 2 2 3 
•  » » 5 months ago, # ^ |   +13 ans[v] will not be lo + 1. It will be the current size of vector. Just changed that got AC: https://atcoder.jp/contests/abc165/submissions/12675337
•  » » » 5 months ago, # ^ |   +3 Sorry my bad. I thought the length of LIS at node v. Thanks a lot for your help.
 » 5 months ago, # |   0
 » 5 months ago, # | ← Rev. 2 →   0 How does the checker work in E? chokudai
•  » » 5 months ago, # ^ |   +9 For all the pairs given by the user check their difference both ways. Like 1 and 10 will have difference 1 and 9. These differences should be all different. So you can check in O(M).
 » 5 months ago, # |   -6 I can't understand why my A solution fails Here's my codek=int(input()) a,b=map(int,input().split()) if b-a+1>=k: print('OK') else: print('NG')can anyone point out my mistake
•  » » 5 months ago, # ^ |   0 a=b=k
•  » » » 5 months ago, # ^ |   0 thanks.i misunderstood the question
 » 5 months ago, # |   0 why would I get WA for problem.E #include #define x first #define y second #define pii pair #define sz(x) (int)(x).size() #define all(x) (x).begin(),(x).end() using namespace std; typedef long long LL; const int maxn = 1005; int main(){ int n,m; cin >> n >> m; vector ans; int L = 1,R = n; while(m){ if(L+n-R == R-L) L += 1; else{ ans.push_back(pii(L,R)); L++; R--; m--; } } for(int i = 0;i < sz(ans); ++i) cout << ans[i].x << " " << ans[i].y << '\n'; return 0; } `
•  » » 5 months ago, # ^ |   0 I found bug!
 » 5 months ago, # | ← Rev. 2 →   +24 I believe the test files for the problem E were incorrect. Instead of n <= 100000 , it should be m <= 100000 . If I write an assert statement for the value of n being less than or equal to 1e5, the verdict is RE, while for 2e5+2 it is AC.
•  » » 5 months ago, # ^ |   +5 Oh, there was a clarification as well, my bad. :(
 » 5 months ago, # |   0 Problem F:I have used LIS(nlogn) with B.F.S. but getting T.L.E......please help. https://atcoder.jp/contests/abc165/submissions/12695808
•  » » » 5 months ago, # ^ |   +3 I have used dfs but got TLE Here is the link: https://atcoder.jp/contests/abc165/submissions/12791770
•  » » » » 5 months ago, # ^ | ← Rev. 2 →   +3 You shouldn't pass a "vector L" in a function.You know,vectors are like arrays,so they require time to pass between functions.Try changing it to" vector &L",which passes a "virtual" vector(like a pointer).That shall get an AC.
•  » » » » » 5 months ago, # ^ |   +3 Or you can make L an array out of the dfs functions.My code used just that.
•  » » » » » » 4 months ago, # ^ |   +3 Ok thanks. But can you figure out complexity of that code
•  » » » » » » » 4 months ago, # ^ |   +3 O(n log n) for dp,plus a constant(of the vector).It's good enough.
•  » » » » » » » » 4 months ago, # ^ |   +3 Sorry for my code?
•  » » » » » 4 months ago, # ^ |   0 Can you figure out the complexity of my above code?
•  » » » » » » 4 months ago, # ^ |   0 O(n^2)(for passing the vector).
•  » » » » » » » 4 months ago, # ^ |   0 Thank you I got the concept. Whenever we pass a vector by value it copies the content rather than updating it which is costly
 » 5 months ago, # |   +3 Here is my list of submissions.You can use that as reference.
 » 5 months ago, # |   0 Why are there different results when using GCC and Clang? There are 4 testcases that fail to pass, but my method has no problem. So I checked the official testcase and the input and output, and found that the final problem is that GCC and Clang have different results. I want to know why? ? ? ! ! ! here is my two submission:(the first is AC and the second is WA,but the code is exactly the same!) Your text to link here... Your text to link here...
•  » » 4 months ago, # ^ |   0 Wangxuelong, the defined arrays a,b,c,d should have length 51 if you intend to write into them at positions 1, ..., 50 — this causes your code to write outside of bounds of the arrays, causing undefined behavior (it can still theoretically work, but also the compilers decided to zero out all variables in your program, it would still be a valid thing to do according to C++ spec — the compiler is free to do anything it wants when you do out of bounds access).
•  » » » 4 months ago, # ^ |   0 Thank you very much!
 » 5 months ago, # |   0 For E detail explanation with examples and code check here
 » 5 months ago, # |   0 Can someone suggest similar problems to C?
•  » » 4 months ago, # ^ |   0 search for backtracking problems
 » 3 months ago, # |   0 Can anybody find me the bug with this solution for problem C? Since both n and m is very small, I literally checked all possible combinations of the first m numbers using bit masking, but for some weird reasons, the combinations are not being properly generated, please help me in finding the potential bug in this submission.
 » 2 months ago, # |   0 For E，can some one tell me why this is wrong: void solve() { cin>>n>>m; int now=1; for(int i=1;i<=m;i++) { cout<
•  » » 2 months ago, # ^ |   0 My bad,I find the bug