### ch_egor's blog

By ch_egor, 3 years ago,

Thanks for the participation!

1501A - Alexey and Train was authored by Aleks5d and prepared by 4qqqq

1501B - Napoleon Cake was authored and prepared by KAN

1500A - Going Home was authored and prepared by wrg0ababd

1500B - Two chandeliers was authored by jury and prepared by Siberian

1500C - Matrix Sorting was authored by Endagorion and prepared by NiceClock

1500D - Tiles for Bathroom was authored by meshanya and prepared by KiKoS

1500E - Subset Trick was authored and prepared by isaf27

1500F - Cupboards Jumps was authored and prepared by Akulyat

• -273

| Write comment?
 » 3 years ago, # | ← Rev. 3 →   -22 Thanks for the round and the fast editorials!UPD: It seems that many participants hate this round because of unclear statements, weak pretests or main tests, too hard time limits and so on. But I think these problems are interesting and challenging, aren't they?
 » 3 years ago, # |   -7 Thanks! :)
 » 3 years ago, # |   +69 1A can be solved using FFT. 109885329
•  » » 3 years ago, # ^ |   -20 can anyone explain that how does n^2 sol pass in div 2-C. as,(4≤n≤200000) thanks in advance :-)
•  » » » 3 years ago, # ^ | ← Rev. 2 →   -30 since, 10^8 operations can be done atmost in 1sec. so, in 2sec we can do 2 * 10^8 operation so n^2 is probably not gonna work how then n^2 is working. Also I had submitted the n^2logn approach and it got accepted but How?
•  » » » » 3 years ago, # ^ |   0 So, there is 10^16/10^8 = 10^8 "1sec" in one "2sec".
•  » » » » » 3 years ago, # ^ |   +2 sorry, I dint get you.
•  » » » » » » 3 years ago, # ^ | ← Rev. 2 →   +19 Okay, if we are talking about seconds, 2 seconds = 2 * 1 second, 1 second two times. So if we can do n operations in 1 second, it is 2 * n in two second, not n^2. 10^8 * 2 != 10^16, it is much smaller. 10^16 = 10^8 * 10^8 = 10^8 * (2 + 99999998) = 10^8 * 2 + 10^8 * 99999998.
•  » » » » 3 years ago, # ^ |   0 Wow
•  » » » » 3 years ago, # ^ |   0 Can we iterate till 100000000000000?
•  » » » » » 3 years ago, # ^ | ← Rev. 3 →   +3 try using those new variables (ds, sum) in some calculations and you will get the TLE you're looking for. I think that the compiler saw that you didn't use them so it didn't bother to run those loops. I did some experiments in the past on those types of loops and if the optimizations flags are set on, the compiler will ignore any loop if it's obvious that the rest of the code is not using anything related to those loops. I hope you understand what I mean, and if you're looking for more information about this topic, you can try googling c++ optimization flags.
•  » » » » » » 3 years ago, # ^ |   0 https://mirror.codeforces.com/contest/1501/submission/109923571not gettting TLE
•  » » » » » » » 3 years ago, # ^ |   0 There is something called as Compiler Optimisation, may be it's because of that, basically you are doing something in a loop which can can be done mathematically, so while execution instead of using the loop the value of ds is calculated mathematically.
•  » » » » » » » » 3 years ago, # ^ |   +5 its actually because of int overflow.as u can see, it does TLE with 1,000,000,000.
•  » » » » » » » » » 3 years ago, # ^ | ← Rev. 2 →   0 Nice observation, thanks
•  » » » 3 years ago, # ^ |   +11 There are a total of n*(n-1)/2 pairs of two numbers possible. So there can be maximum n*(n-1)/2 different sums possible. And from the constraint a[i]<=2.5*10^6, then answer always exists. So, when n>4000, then there always exists an answer, hence not giving TLE.
 » 3 years ago, # | ← Rev. 2 →   +15 What does "C" denote to in going home editorial ?
•  » » 3 years ago, # ^ |   +3 Constant, $2 \cdot 2.5 \cdot 10^6$
 » 3 years ago, # |   +159 Two logarithms in B and logarithm in C and these TLs? Are you crazy? ;_;
•  » » 3 years ago, # ^ |   +6 Isn't there a linear algorithm for B, My code[submission:109895054]passed tests but I don't know if its correct considering many smart people didn't get this algorithm
 » 3 years ago, # |   +32 Div 2 C was hard :(
 » 3 years ago, # |   +3 min(n^2,n+C)......I think too much.
•  » » 3 years ago, # ^ |   0 How is O(n2) solution working when 4 <= N <= 200000 ? I know the time complexity given above is O(min(n2, n+C)). Where is this (n+C) coming from ?When the answer is "NO" we are iterating over all the possible pairs O(n*(n-1)/2). So when the value of N = 200000, shouldn't it give TLE ?
•  » » » 3 years ago, # ^ |   +7 The answer will not be "NO" when $n$ is big enough.
•  » » » 3 years ago, # ^ | ← Rev. 2 →   +8 You can think of the pigeonhole principle.Remember that there are always four distinct indices $x, y, z, w$ such that $a_x + a_y = a_z + a_w$ ($= S$) when there are at least four distinct pairs of indices $(x_1, y_1), (x_2, y_2), (x_3, y_3), (x_4, y_4)$ (indices may be repeated across them) such that $a_{x_1} + a_{y_1} = a_{x_2} + a_{y_2} = a_{x_3} + a_{y_3} = a_{x_4} + a_{y_4} = S$.Let's imagine we are running our $\mathcal{O}(n^2)$ bruteforce and trying every pair; for every pair $(i, j)$ we compute its sum $a_i + a_j = S$ and increment the count on how many times we have seen the sum $S$. Given that the maximum sum of any pair is $2*C$, the "longest" it would take the bruteforce to see one sum $S$ occurring four times is around ~$3 * (2 * C) = \mathcal{O}(C)$. Therefore, if a solution exists, it will be found in time $\mathcal{O}(C)$. If there's no solution (we tried all pairs), it was the case that (roughly) $n^2 \le 3 * (2 * C)$ (or something close to this).
•  » » » » 3 years ago, # ^ |   0 Sir,can you kindly say what is this C?
•  » » » » » 3 years ago, # ^ |   +3 $C = 2.5⋅10^6$ is the maximum value an element can take.
 » 3 years ago, # |   +88 Can I see the model solution to B, with complexity O((n+m)⋅log(n+m)⋅log(k⋅(n+m)), that passes the constraints? How was the TL set? Thanks
•  » » 3 years ago, # ^ |   +73 +1
•  » » 3 years ago, # ^ |   +9 I'm curious about the running time of the author's code and if he had done strict optimization on constant.Or maybe the author thought 1 second equals to 1e9 complexity on codeforces?I'm considering adding "#pragma GCC optimize("Ofast")" into my default header, though my code used 1544ms this time without this ;_;
•  » » » 3 years ago, # ^ |   0 I can't imagine that complexity passing even with some constant optimizations. Even if it passed, it would be bad to set TL based on a heavily constant optimized solution with terrible complexity. At least you passed, I couldn't fit my O((n + m)log(i64)) into TL, but that might be just because I'm weak :D. (also I don't have any lib so I copied from cp-algo and apparently it's slow xd)
•  » » » » 3 years ago, # ^ | ← Rev. 2 →   +6 Actually I too can't imagine this complexity can pass the test in this TL. And I think the TL of this problem is undoubtedly inappropriate, and it seems like a naive mistake.Yet I'm simply curious about what had happened when this limit was being set. As far as I know, some authors would just set the TL by the running time of his/her code times 2 or even 1.5 without thinking twice.
•  » » » » 3 years ago, # ^ |   +9 BTW, My complexity is also O(n+m)log(1e18), no two logarithm but still not too far from the TL.
•  » » 3 years ago, # ^ |   +18 My solution passes, but I have log(n)^2.109863770
•  » » » 3 years ago, # ^ |   +1 It's still very close to the TL. Anyways, orz.
•  » » » » 3 years ago, # ^ |   0 Mine passes as well, not even close to tl wtf.
•  » » 3 years ago, # ^ | ← Rev. 3 →   -16 There is a linear algorithm right?Why not explain that in editorial?(My linear algorithm submission:109895054)
 » 3 years ago, # |   +13 Div.1C has some similarities with Bucket Sort.
 » 3 years ago, # | ← Rev. 5 →   +15 I decompose 2C into several cases:1) We have 4 copies of a value X (e.g. 1 1 1 1 2 3) => YES2) We have 2 or 3 copies of a value X; and we have several such X (at least 2), (e.g 1 1 2 2 2 5 10) => YES3) We have 2 or 3 copies of a value X; and there is exactly one X like that (e.g. 1 2 2 2 100 7 9) => two pointers for checking whether we have u and v such that u < X < v and u+v = 2*X => YES/NO.If YES, it is ok. Otherwise, we remove duplicated elements and continue with case 4.4) We have only distinct values (e.g. 1 2 5 9 11 13 ...)If N*(N-1)/2 > 5*10^6: we will have two different pairs (x,y)and(z,t) that meets the condition; because of the Dirictle lemma. Just check bruto-force the first sqrt(10^7) elements.Otherwise, perform O(n^2) algorithm to check.
•  » » 3 years ago, # ^ |   +3 Can you elaborate on Dirictle lemma?
•  » » » 3 years ago, # ^ | ← Rev. 3 →   +16 It is something like : if you put N items into M boxes with N>M; you will have a box with at least 2 items.So, given that we have an array of size N with distint non-negative values and we have n*(n-1)/2 pairs (u+v), and if n*(n-1)/2 > 5,000,000; we should have a YES answer.
•  » » » » 3 years ago, # ^ |   +14 Is it same as pigeon hole principle?
•  » » » » » 3 years ago, # ^ |   +13 Yes, it is the same. I just do not remember the name you mentioned.
•  » » » » 3 years ago, # ^ |   +4 Great explanation! it helped me to completely understand why brute force sol. works.Thanks.
•  » » 3 years ago, # ^ |   0 Why do we have to check only sqrt(10^7) no.s , Here we are on addition so shouldn't we check till 2.5*10^6 , for each loop
•  » » » 3 years ago, # ^ |   +1 it is since using the first sqrt(10^7) elements of A, you create more than 5*10^6 values of form A[i]+A[j] with i
•  » » » » 3 years ago, # ^ |   0 Okkk , Thanks , I got it
 » 3 years ago, # | ← Rev. 2 →   +5 Can you unhide the main tests? I can't wait to find why I FSTed:(
 » 3 years ago, # | ← Rev. 2 →   +3 Div1 B can be solved in O(n log k). Crt and Gcd is not necessary .
•  » » 3 years ago, # ^ | ← Rev. 2 →   -10 code: Spoiler/* { ###################### # Author # # Gary # # 2021 # ###################### */ #include #define rb(a,b,c) for(int a=b;a<=c;++a) #define rl(a,b,c) for(int a=b;a>=c;--a) #define LL long long #define IT iterator #define PB push_back #define II(a,b) make_pair(a,b) #define FIR first #define SEC second #define FREO freopen("check.out","w",stdout) #define rep(a,b) for(int a=0;a'9'){ // ch=getchar(); // } // while(ch>='0'&&ch<='9'){ // x=(x<<1)+(x<<3)+(ch^48); // ch=getchar(); // } // return x; //} const int INF=0x3f3f3f3f; typedef pair mp; /*} */ const int MAXN=5e5+233; int n,m; LL k; int q[MAXN]; int a[MAXN]; int b[MAXN]; map pos; vector v; bool vis[MAXN]; bool check(LL x){ LL tur=x/m; LL Lm=x%m; LL sum=0; for(auto it:v){ sum+=q[it]; } if(tur/v.size()&&k/(tur/v.size())>1; if(check(mid)){ l=mid; } else{ r=mid; } } cout<
•  » » » 3 years ago, # ^ |   +8 Any tutorial?
•  » » » » 3 years ago, # ^ |   +2 Find the loop section and binary search
•  » » » » » 3 years ago, # ^ |   +5 I don't understand. Do you mean precalculate length lcm(n,m) and find answer to k using binary search? I am a little dumb here becuz the loop section's collision might need O(nm) to find if n and m are coprime.
•  » » » » » » 3 years ago, # ^ |   0 You can see the "while(!vis[now])" part in my code , it found all the loop section.
•  » » 3 years ago, # ^ |   0 I might be wrong but I believe if one uses CRT, but not BS on the answer, it is O(NlogN). We compute the values mod mmc(N,M) that have the same color.
•  » » 3 years ago, # ^ | ← Rev. 2 →   +18 It could be solved in O(N + M) to. Binary search is not necessary, one could just "simulate". In case someone is interested: code
•  » » » 3 years ago, # ^ |   0 your submission hype link is broken and no one found lol
•  » » » » 3 years ago, # ^ |   0 Fixed. Sorry about that
•  » » 3 years ago, # ^ |   0 If my math is correct, it can be solved in O(N) (or smth like O(N+M+log(N+M)), but linear in general)126387236
 » 3 years ago, # |   -53 This editorials is so fast that I'm be so surprised of it!
 » 3 years ago, # |   +8 I have a randomised solution for div2C/div1A and I'm not sure if I cheesed system tests or if it's supposed to pass. Can someone take a look at it and hack if possible? Otherwise, if it's supposed to pass, can someone tell me the probability of failure?Submission: 109876872
•  » » 3 years ago, # ^ |   0 That is a nice try..
•  » » » 3 years ago, # ^ |   -8 And it did pass system tests :)
 » 3 years ago, # |   +9 I got a FST in Div1B.But when I submit the code again after contest , it accepted (but 1981ms).And when I submit the same code again with C++17(64) , it accepted and only ran 1653ms.What a pity...My submisson during contest:109857178Submisson after contest:109891513With C++17(64):109891826
 » 3 years ago, # | ← Rev. 2 →   +13 I found the GFG page, but looking at it I thought it wouldn't pass. After the contest and reading some comments here, I thought it just might.I tried, and it got AC. Smile in pain. Hehe. GeeksForGeeks article
 » 3 years ago, # |   0 Please can someone explain me this : During the contest I submitted ABC and there it said pretest passed and now it is showing -1 in A and C, saying WA in tc 6(for A) and TLE in C problem. How does this happen?Should not they show this during the contest, that i have done 2 questions wrong ?? Please if someone could help me understand what happened ? I am really frustrated rn
•  » » 3 years ago, # ^ |   0 Since it would take too much time to run over all the testcases during the contest, Codeforces divides the testcases to be "pretests" and "system tests".Passing the pretests doesn't mean that you solved the problem (though it should...).
 » 3 years ago, # |   +208 Good contest with strong pretests, especially in problem B and problem C.What's more, the tl of problem B and the ml of problem D are very friendly. No one can get TLE or MLE on them.
•  » » 3 years ago, # ^ |   +76 I think that you should say clearly that it's a sarcasm, it might be hard to get it.
•  » » 3 years ago, # ^ | ← Rev. 4 →   +53 Can't speak for D, but, unless my solution is very wrong and tests are extremely weak, binary search in div1B isn't needed at all. In fact, I solved it in $O((n + m)\log(n + m))$, where the $\log$ comes from a single sorting of a vector with up to $\min(n, \, m)$ elements.Sketch of solution. Iterate over the colors and make a vector $s$ of all solutions to the system that you find (if for some color there are no solutions, ignore it). Then sort the vector. Now set $ans$ to $\displaystyle \text{lcm}(n, \, m) \cdot \left\lfloor \frac{k}{\text{lcm}(n, \, m) - \text{size}(s)} \right\rfloor$ and reduce $k \mod (\text{lcm}(n, \, m) - \text{size}(s))$. Finally, iterate over the elements of $s$ and stop at the first index $i$ such that $s[i] - i \ge k$. Then it is easy to update $ans$ to the correct value.
 » 3 years ago, # |   0 How to solve Div1B/Div2D ?
 » 3 years ago, # |   -8 Can anybody please explain why this solution for div2 A is giving wrong answer https://mirror.codeforces.com/contest/1501/submission/109849523
•  » » 3 years ago, # ^ | ← Rev. 12 →   0 nvm, you figured it out yourself either way
 » 3 years ago, # |   +5 109860426Who wants to hack my randomized div1A?For n <= 150, I use a quartic brute force.For n > 150, I use MITM, where I partition the array into two halves, and randomly select 10^6 pairs from each half, and check for any common sums.
 » 3 years ago, # | ← Rev. 2 →   +8 ML in D was brutal. If only $q \le 9$ instead of $10$ or number of colors was up to $2\cdot 10^6$ instead of $2.25 \cdot 10^6$ it would really be easier xd
 » 3 years ago, # | ← Rev. 2 →   0 Div-2 C solution in gfg:some modifications will do
•  » » 3 years ago, # ^ | ← Rev. 2 →   -7 .
•  » » 3 years ago, # ^ | ← Rev. 4 →   0 .
 » 3 years ago, # |   +1 Shitty Round especially statement of problem DIV2A.
 » 3 years ago, # |   +5 109889803For 1500C - Matrix Sorting , the $O(nm^2)$ approach could be optimized to $O(\frac{nm^2}{w})$ using bitset, which could pass the tests.
•  » » 3 years ago, # ^ |   0 Yes, that's what I did in the contest. I really think it's a good problem, but the limit seems quite tight. I douted whether it would pass before submitting (it passed though).
•  » » 3 years ago, # ^ |   0 $O(nm^2)$ can be pass the tests too. So Incredible! 112190603
 » 3 years ago, # | ← Rev. 2 →   +34 I had figured out a $O(nm^{2})$ solution for 1C, but now I don't even understand how the editorial reaches $O(nm^{2})$, let alone understanding optimising it to $O(nm)$. The editorial is hard to understand. I think the optimising part made it too difficult a problem for its position as 1C ?!In particular, can someone please explain this part: If two rows are in the same class, then the columns that we applied had the same values. Then, we need to find a column that does not break the sequence between the rows inside each of the classes. Let's iterate through such a column every time. What values are we talking about?
 » 3 years ago, # |   +37 An alternative approach for Div1A.Let us prove that if $n > \sqrt{8\max a} + 2$ then we can always find such a quadruple. Indeed, sort $a$ in ascending order and consider the differences $a_2 - a_1, \, a_4 - a_3, \, \dots, \, a_{2k} - a_{2k - 1}, \, \dots$ These are $\left\lfloor \frac{n}{2} \right\rfloor$, so there are two of them which are equal. If that weren't the case, we would have $\displaystyle a_n \ge \sum_{k = 1}^{\left\lfloor \frac{n}{2} \right\rfloor} (a_{2k} - a_{2k - 1}) \ge 0 + 1 + \cdots + \left(\left\lfloor \frac{n}{2} \right\rfloor - 1\right) = \frac{\left\lfloor \frac{n}{2} \right\rfloor\left( \left\lfloor \frac{n}{2} \right\rfloor - 1 \right)}{2} > \max a.$Let $i, \, j$ be such that $a_{2i} - a_{2i - 1} = a_{2j} - a_{2j - 1}$. Then $x = 2i$, $y = 2j - 1$, $z = 2j$, $w = 2i - 1$ is a solution.Now we proceed as follows. We sort $a$, iterate over the even values of $k$ and check if two differences $a_{2k} - a_{2k - 1}$ are equal. If this is the case, we are done. Otherwise, $n < \sqrt{8\max a} + 2$ and we can bruteforce the answer in $O(n^2)$.
•  » » 3 years ago, # ^ |   0 sorry but I can't figure out how $n > \sqrt{8\max a} + 2$ is calculated, could you please give an explaination?
•  » » » 3 years ago, # ^ | ← Rev. 2 →   0 You gotta solve the equation $\frac{\left\lfloor \frac{n}{2} \right\rfloor\left( \left\lfloor \frac{n}{2} \right\rfloor - 1 \right)}{2} > \max a.$ to get this. The inference makes sense, however, I don't quite understand how you bruteforce the answer in $O(n^2)$。UPD: I now understand, use the method as editorial. But then you don't need to do those survey beforehand :<
•  » » » » 3 years ago, # ^ |   0 Exactly as in the editorial solution. Actually, I realize now that the first part isn't needed at all. Because of the proof in the editorial, the second part alone (bruteforce) is sufficient to solve the problem with the given constraints.
•  » » » » 3 years ago, # ^ |   0 Thx for the explaination and I also wonder how to bruteforce in $O(n^2)$
 » 3 years ago, # |   +1 1500A going home. I notice that ai<=2.5*10^6 but didn't investigate into that.. Indeed, $1<=ai+aj<=5*10^6$ for arbitrary i,j. And if we have n distinct elements, we will have $\frac{n*(n-1)}{2}$ pairs of different pair of (i,j). If $\frac{n*(n-1)}{2}>5*10^6 => n>=3162$ you are guaranteed to find an answer. Well, doesn't help to solve this problem.
 » 3 years ago, # |   0 I feel like this approach for div1A/div2C is right but it FSTd. Can someone tell me why?So first i rewrite the eqn as ax-az = aw-ay. Now I just need to find 2 pairs of indices such that their differences are the same.For this, I store all elements in a frequency array and iterate over all differences. for(int i=0;i
•  » » 3 years ago, # ^ |   0 Did you make sure to not repeat some index? Maybe that is the case
•  » » » 3 years ago, # ^ |   0 Yes, if i take the pair {j, j+i} at one iteration, and if freq[j+i]==1, I make sure to not take it again, or else i consider the possibility that it can be taken again
•  » » 3 years ago, # ^ | ← Rev. 2 →   +5 4 2 7 11 16o/p : YES 1 4 2 3your code's o/p : NO
•  » » » 3 years ago, # ^ |   0 Thanks a lot, I got my mistake
 » 3 years ago, # |   +13 div-2D/1B can be solved in linear time. We just need to calculate for each starting position in 1st array, how many matches will be with 2nd array in next m indexes. Here's my AC: 109899040
•  » » 3 years ago, # ^ |   +3 Yup I used a similar approach. Code
•  » » » 3 years ago, # ^ |   +5 Yes, it is too similar lol.
•  » » » » 3 years ago, # ^ |   0 Can anyone of you explain your submissions as it seems that some mathematical principles are hidden in some beautiful lines written out there. Thanks.
•  » » » » » 3 years ago, # ^ |   +9 First I made the 1st array greater than 2nd by swapping.I have made an array named 'c' of size n, such that c[i] represents the no. of dismatches (a[i]!=b[j]) in the next m days if we start from a[i].Mathematically, c[i] = no. of j's such that a[(i+j)%n]!=b[j] and j=0 to m-1Initially all c[i]=m (we assumes all dismatches). Now we can iterate the 'b' array. If b[i] is not present in array 'a', then b[i] won't cause any match irrespective of starting index (won't effect any c[j]). We will simply continue.otherwise if b[i]==a[j] (you can use an additional array/map to find that), we should decrease c[(i-j)%n] by one because we will find a match when we start from (i-j)%n after j indexes.Thus we obtain c array. Let x=0. Now we can just push_back c[x] in a vector and change x to (x+m)%n until it again reaches x=0 ( cycle formed)after that it's just trivial.
 » 3 years ago, # |   0 Can anyone explain why brute force worked in C (going home) even though the constraints are 4≤n≤200000? 2*10^5 should require an O(n) or O(nlog(n)) solution so how O(n^2) worked?
•  » » 3 years ago, # ^ | ← Rev. 2 →   0 Because since 2.5*10^5 is the upper bound on every element the maximum sum of 2 elements can be 5*10^5. Now if you just iterate to get all possible sums they will all be below 5*10^5 and in 1 iteration you get 1 new sum, otherwise you break. So you will never TLE.
•  » » » 3 years ago, # ^ |   0 *upper bound on every element is 2.5*10^6
•  » » » » 3 years ago, # ^ | ← Rev. 3 →   0 Alright, but it's still more than enough. The solution is actually O(n).
•  » » » » » 3 years ago, # ^ |   0 now i am more confused....
•  » » » » » » 3 years ago, # ^ | ← Rev. 2 →   +1 Ok imagine you have a million elements but upper bound is say 10, do you need to do O(n^2) over a million elements to confirm that you will get a repeating sum? No, as maximum possible sum of 2 elements is only 20 you will only have at maximum 20 different values of sum possible, this is the whole basis of this problem. As another user suggested this is known as pigeonhole principle.
 » 3 years ago, # |   0 What is the variable "y" in 1B's tutorial?
 » 3 years ago, # |   +8 Thanks for fast and clear editiorials!I quickly(I hope so) solve two problems, when I come to think about C, I had a challange. But finally I solve it. And the great thing is I have a rank of 239! I'm really excited about that:-)The problems are really great and I enjoyed it a lot, thanks!
•  » » 3 years ago, # ^ |   +9 Nah the editorial is so confusing IMO
 » 3 years ago, # |   -10 In Div2 C ( Div1 A ) why the brute force using map and checking sum of 2 pair of indices passes the time limit. Its time complexity is O(n^2) still it passes. Code: https://mirror.codeforces.com/contest/1501/submission/109901974
•  » » 3 years ago, # ^ | ← Rev. 2 →   0 I Misread...
•  » » » 3 years ago, # ^ | ← Rev. 2 →   0 Actually i was trying to show that even using map, brute force O(n^2) is getting passed .. my question was- why is this getting passed through the time limit ?
•  » » » » 3 years ago, # ^ |   +1 Because maximum element is 2.5*10^6 so maximum sum of 2 elements is 5*10^6. So you can get at max 5*10^6 different values of sums before encountering a repetition. So once you find a sum again for different indices you can just break the iteration. That's why time complexity is given as min(O(n^2), O(n+C)).
 » 3 years ago, # |   +53 My code for div1B got TLE result. submissionAfter using fread,it accepted. submissionThe complexity of the code is $O((n+m)log(nm))$ So , why is the time limit so hard ?
 » 3 years ago, # |   0 again my A FST. is it weak pretest or my blunder? A Submission
•  » » 3 years ago, # ^ |   0 Both.
 » 3 years ago, # |   0 will someone tell me what is wrong with this code https://mirror.codeforces.com/contest/1501/submission/109882653 ? it is showing runtime error on test 8.
 » 3 years ago, # |   +3 Why aren't results for div 2 out yet?? I see div 1 results are already out.
 » 3 years ago, # |   0 [TWO CHANDELIERS] Can someone explain me over what variable you can do binary search? I don't get the solution at all :(
 » 3 years ago, # |   0 This could just be my own perception, but since restrictions on contest writers were tightened, I have found the contests much more difficult. Today I couldn't solve a single question in Div 1. I think that's the first time that's ever happened, but in general the recent contests have been tough.
•  » » 3 years ago, # ^ | ← Rev. 2 →   +5 :< Dude you are really hardworking. This used to be a complaint but it is now a comfort from me after checking your profile. Keep up and do some problems that you never hear of. Wish you luck.
 » 3 years ago, # |   +30 Very beautiful, careful and short solution by olympiad participant teraqqq. May help to understand the solution.https://pastebin.com/uhhe3c4v
•  » » 3 years ago, # ^ |   0 What exactly does vector cut keep track of? Seems like it stores some kind of property for the rows?
•  » » » 3 years ago, # ^ |   +5 In the final state of B, the equivalence classes are sub-arrays, so we store did we cut our classes or not.
 » 3 years ago, # |   +6 Sadly ch_egor have not authored any problem but suffered downwotes for managing the contest and problemset. It is not fair.
 » 3 years ago, # |   0 In Div2 C, I used an intuitive approach to solve that worked. Basically, I iterated over differences (ax — az) from 0 to k*C/N, where C = 2.5*10^6, N is the input size, and k is some constant (say 2) and then I checked whether four such indices exist or not. My question is how to prove that only checking first k*C/N differences works? Also, what is the tight lower bound for such k?
 » 3 years ago, # |   0 How are we expected to know that the actual value of n used in the main tests is much smaller than the given constraint in div2-C question? An O(n^2) solution should not be accepted according to the given constraints but many people got away with it due to weak test cases. This should be rectified somehow
•  » » 3 years ago, # ^ |   0 Did you read the editorial? Time complexity is min(O(n^2,n+C)).
 » 3 years ago, # |   0 I have trouble understanding problem div1 A / div2 C Why is the condition in the editorial sufficient? If we have 4 pairs such that their sum is equal then there is a solution. However, that doesn't imply that there will always be 4 such pairs if there is a solution to the problem.In other words, what is the proof that there exists a solution to the problem if and only if there are these 4 pairs that are described in the editorial?
 » 3 years ago, # | ← Rev. 2 →   -10 Here is the normal solution of d1a instead of the authors' unobvious solution: If $n<10000$ run the $n^2$ solution, else sort the numbers and find the pair of pairs of adjacent numbers with the same difference, also the indices should be different. It always exists because $10000^2 > 2.5 \cdot 10^6$.
 » 3 years ago, # |   0 I submitted the code when the overall evaluation failed in the competition and passed it directly after the competition. The machine was too slow during the overall evaluation, which led to unfair treatment. Please restore it to me！！！！！duringhttp://mirror.codeforces.com/contest/1500/submission/109859256afterQuite the same
 » 3 years ago, # | ← Rev. 2 →   0 How to construct a sequence of number for n = 1570 whose answer is "NO" for div1A/div2C ? I found that 4-th example is that situation, however, I can't construct it. Can someone give me an idea ?
•  » » 3 years ago, # ^ | ← Rev. 3 →   0 $1, 2, 3, 5, 7, 10, 13 \dots$
•  » » » 3 years ago, # ^ | ← Rev. 2 →   0 The last element is approximately equal to $785^2$ and one can prove all the pairwise differences are different
•  » » » 3 years ago, # ^ |   0 Can you please elaborate on how you came up with this sequence?
•  » » » 3 years ago, # ^ |   0 Output will be YES. As, 5+7=2+10
•  » » » » 3 years ago, # ^ |   +5 oh sad let me fix it
•  » » 3 years ago, # ^ |   0 https://cstheory.stackexchange.com/questions/32126/is-there-an-efficient-program-for-generating-a-sidon-sequenceUsing the first answer you can construct sequence of size $\sqrt{C}$
 » 3 years ago, # |   0 DIV2 C question was hard to think how it works in N^2 approach even N was in that range which generally doesn't fit in N^2 approach .. many of those (not all of them) get accepted to that question without knowing proper reason.. LOL..
•  » » 3 years ago, # ^ |   0 Even absolute newcomers with just a little idea of complexity won't write O(N^2) solution at this constraints without reasoning. So, what are you talking about? They at least got the intuition and getting it isn't hard. It's just getting the fact that if you have large N, then you would have duplicates in sum simply because of so much options to choose sum and limited options for sum.So, not actually many of them, only like 1-2% at most without knowing reason tried out O(N^2).
 » 3 years ago, # |   0 Problem C. Going Home. In statement n is <= 200000. So why O(min(n^2,n+C)) doesnt have TLE?
 » 3 years ago, # |   0 In the problem B, the numbers are distinct which isn't stated in the statements. That's a major issue.
 » 3 years ago, # |   0 what is "y" in the editorial of div1B/div2D?
 » 3 years ago, # |   0 They added few more test cases in Div 2 Problem C. Why my previous AC code is giving TLE on Test Case 73?
 » 3 years ago, # | ← Rev. 2 →   +1 I haven't seen anyone else do this, but div. 2 B can be solved with Fenwick. 109919812The idea is basically to keep a BIT of the number of layers of syrup on each layer of cake.
 » 3 years ago, # |   +1 I'm going crazy. Can anyone tell me why my solution gives WA on test 12? problem div2.D and my code, Thanks.
•  » » 3 years ago, # ^ |   +1 maybe this could help.
•  » » » 3 years ago, # ^ |   0 Thanks, I will check it.
 » 3 years ago, # |   0 How is C:Going Home Accepted in quadratic time?
 » 3 years ago, # |   0 div1A I got ac,but my code 110017025 was wrong wrong test: 5 1 1 1 1 4
 » 3 years ago, # |   0 [Div-1 'B'] If n and m are not coprime, participant can make transition (n,m)→(ngcd(n,m),mgcd(n,m)), solve new equations, and then make reverse transition How to do that?
 » 3 years ago, # |   0 Can somebody please tell me why my code:110064321 TLEs in Div.2D and any possible optimization I can do? Thanks.
 » 3 years ago, # |   0 My solution for d works in O(max(n, m)) time. So first you check if the solution will be found after n*m days(because that will 100% get both sequences lined up again). To do so you take the smaller array and find how many same numbers it will have in every cycle(1 cycle is min(n, m) days) in bigger array. For example if you have 3 2 1 0 and 3 1, at cycle 0 (3 2 : 3 1) you will have 1 same occurance, at cycle 1 also(2 1 : 3 1) and in others 0.To do so fast you find where every element from smaller array belongs in bigger and to get the position of cycle subtract the index of element in smaller array(so 1 is on index 2 in bigger array but because it is second element in smaller it will belong to 2 — 1 = 1 cycle). After that you just n times add number of different elements in cycles (to do so you just have i — cycle you are currently at which is 0 at start and with every iteration it will become (i + m) % n because 1 cycle is m days so you move m elements on bigger array). After you add all the values(lets say into SUM) of numberofdifferentoncyclei you can check if that number is bigger than k and if it is you add to your answer(int)(k / sum) * n * m and subtract from k (int)k / sum * sum so we now know that k < sum. After that we can just do one more iteration over cycles to find at whichn our sum will become greater than k and get our answer. Check the code for better understanding.110062516
 » 3 years ago, # |   +1 For 1500A - Going Home, I found the editorial's solution really hard to optimize to fit into the 2s time limit. However, if we first do an $O(n)$ pass to filter out the test cases where there is a value with frequency $\ge 4$, or at least two non-unique values (in those cases, a solution can be easily constructed), we could then know that the solution, if it exists, must involve four distinct values. Thus we only need to store up to one pair for each sum (finding the second disjoint pair will allow us to construct the solution) This significantly improves the constant factor for the solution, and easily passes in Kotlin.
 » 3 years ago, # |   0 Matrix Sorting's tests can be passed using O(n*m*m) solution.
•  » » 3 years ago, # ^ |   0 Me too! QwQ
 » 3 years ago, # |   +8 TL for Div 1 E is tooooooo tight !!!
 » 3 years ago, # | ← Rev. 2 →   0 .
 » 12 months ago, # |   0 can anybody please help me with the dynamic programming solution of napolean cake question
 » 6 months ago, # |   0 can any one give a TC to find why my submission gets TL ?