### Stepavly's blog

By Stepavly, 16 months ago, translation,

1475A - Odd Divisor

Problem authors: Stepavly, Supermagzzz

Editorial
Solution

1475B - New Year's Number

Problem author: MikeMirzayanov

Editorial
Solution

1475C - Ball in Berland

Problem authors: Stepavly, Supermagzzz

Editorial
Solution

1475D - Cleaning the Phone

Problem authors: Stepavly, Supermagzzz

Editorial
Solution

Problem authors: Stepavly, Supermagzzz

Editorial
Solution

1475F - Unusual Matrix

Problem authors: Stepavly, Supermagzzz

Editorial
Solution

1475G - Strange Beauty

Problem author: MikeMirzayanov

Editorial
Solution

• +127

 » 16 months ago, # |   +15 F was almost a duplicate of USACO's 'Left Out': http://www.usaco.org/index.php?page=viewproblem2&cpid=942 Really like the idea regardless
•  » » 16 months ago, # ^ |   0 also it makes no sense to apply the same operation more than once (by the property of the xor operation).Can someone explain this line in the F editorial? I understand that applying the operation twice on the same row/column would again switch it back to the previous, but how applying the operation to a row, then to a column, and then again to the same row doesn't make sense?
•  » » » 16 months ago, # ^ |   +1 bruh did you reply to my comment just so that it'd appear higher up lol? anyways, that'd be the same as just applying the operation to the column
•  » » » » 16 months ago, # ^ |   +8 Haha yes, plus this was the only comment regarding problem F. Thanks a lot, got it!.
•  » » » » » 11 months ago, # ^ |   0 Hi can you can explain , how you got it
•  » » 15 months ago, # ^ |   0 in E , i am having trouble while taking modwhen i submitted without taking mod while calculating factorial then i got overflow. 106346070but when i changed and gave mod while calculaating factorial itself then , i got the answer as 0 106343305pls someone help me out.
•  » » » 15 months ago, # ^ |   0 Hi! I'm still looking through your code, but maybe you can help me out: is it possible you're dividing factorials? I had the same issue, so if it's your case, too, than I can help.
•  » » » » 15 months ago, # ^ | ← Rev. 2 →   0 In my first attempt 106389327 I explicitly calculated factorials and divided them, and got the exact same error. In my case the mistake is that you can't divide mods. I fixed the problem by calculating pascal's triangle instead of factorials: 106392329. Probably you can still use factorials but you need to use some other things like this. I hope it will help.
 » 16 months ago, # |   0 Hopefully the problems regarding servers get fixed before the next contest.
 » 16 months ago, # | ← Rev. 4 →   +28 Thanks for the contest! I recorded my participation and narrated over it -- https://www.youtube.com/watch?v=0eZsX0BWtyY (video is done processing + I've added chapter timestamps).
•  » » 15 months ago, # ^ |   0 i can not understand your solution to problem c can you make it clear more !!!
 » 16 months ago, # | ← Rev. 2 →   +27 Interesting problemset, not too tough nor too easy. It was definitely more on an easier end, but considering it was a Div3 I enjoyed it.I especially liked the appearance of many different parts of CP and different topics, not just ad-hoc problems, e. g. binary search, dp, multiplicative inverse/binary exponentation, math, observation...I think beginners can greatly benefit from this experience regardless of the long queue. Thanks to the problemsetters!UPD: For those wondering where binary search appeared — apparently I overcomplicated the fourth problem and solved using binary search, Might have not been the best idea, but made it a nice problem for me. :P
•  » » 16 months ago, # ^ |   0 Binary was good as well for me
 » 16 months ago, # |   +4 i solved D using dp , never realized it could be done using binary search
•  » » 16 months ago, # ^ |   0 Could you please explain your approach?
•  » » » 16 months ago, # ^ |   +4
•  » » 16 months ago, # ^ |   0 solution please!
•  » » » 16 months ago, # ^ |   0
•  » » 16 months ago, # ^ |   0 Hey,I tried D with priority queues by making different queues more important and less important respectively. But it gave wrong ans with some case.This is my code https://codeforces.com/contest/1475/submission/105424077Any suggestion in code or logic will be helpful.
•  » » » 16 months ago, # ^ |   0 you can see my solution. I have also used the same approach. https://codeforces.com/contest/1475/submission/105382749
•  » » » » 16 months ago, # ^ |   0 if (r + r1 <= i) { ans += 2; m -= i; imp.pop(); reg.push(r); // trace(i); } else { // trace(r); ans++; m -= r; }Thanks brother got the error, I was doing m-=(r+r1) but acc. to your sol. r1 can be used afterwards or it may happen that it is not used. This is what i thought after seeing your solution, if anything else you wanted to add that you think of or proof of this pls share it would be very helpful in future contests.
•  » » » » » 16 months ago, # ^ | ← Rev. 2 →   0 no you got it right. It'a a fairly straight greedy problem. You just have to choose maximum memory you can delete with 2 convienience.
•  » » » » » » 16 months ago, # ^ |   0 okk thanks
•  » » » 16 months ago, # ^ |   0 Try thinking about this test case: 1 4 8 4 1 1 4 3 1 1 1 2 2 
•  » » » » 16 months ago, # ^ |   +1 thanks got the error, i was subtracting two regular apps at a time but it should be one at a time.if anything you want to add or can we proof this observation, it would be helpful in future contest.Thanks
•  » » 16 months ago, # ^ |   0 what are the DP states and state transitions used in your solution?
•  » » » 16 months ago, # ^ |   +6 initially i calculated the sum of convenience points . divided the memory in two arrays based on the type of application and sorted both the arrays in ascending order . dp states were the convenience points, i calculated what is the maximum application memory that can be removed if i loose k convenience points . dp[i] stored the maximum memory possible , along with how many regular and important applications have been used for it. therefore dp[i] = {max,{index upto which regular have been used,index upto which imp has been used }},here i is the convenience points lost which is (index upto regular + 2*index upto imp) . for transition - dp[i] = max(dp[i-1] + maximum memory from regular array that can be used,dp[i-2] + maximum memory from imp array that can be used) then update the index of regular and important that have been used for that state . After the calculation , i just traversed over the array and found the first index where the memory >= m . here's my solution — https://codeforces.com/contest/1475/submission/105395940
•  » » » » 16 months ago, # ^ |   0 Can you tell me why you choose the dp[i-2] route if both dp[i-1] and dp[i-2] are equal in your solution ?
•  » » » » » 16 months ago, # ^ |   0 dp[i-1] will store the maximum sum that can be achieved when i loose i-1 convenience points and dp[i-2] will store the maximum sum that can be achieved when i loose i-2 .so since i am loosing more convenience points in (i-1) rather than (i-2) , dp[i-1] > dp[i-2]. for example if i can loose 4 convenience points and the maximum sum achieved is a , and if i can loose 5 convenience points and the maximum sum achived is b , then b > a .
•  » » 16 months ago, # ^ |   0 the subset DP approach? where you each cell in dp shows sum achieved with min convenience points.?
•  » » » 16 months ago, # ^ |   0 dp[i] stores the maximum sum achieved when we loose i convenience points . along with this it also stores the {index upto which regular applications have been used , ,index upto which important applications have been used} = {a,b} , so we can say that i = (a + 2*b).
•  » » 16 months ago, # ^ |   0 i have also solved it but it is giving me memory limit exceeded... as i am taking a dp of size dp[N][sum_of_all_elements] please reply Bhavyashah12050
•  » » » 16 months ago, # ^ | ← Rev. 3 →   0 knapsack dp will give tle coz if n^2 and it will not fit in memory because the sum can be >=1e9 , it is not possible to make an array of this size , so instead iterate on the total sum of the convenience points , my approach was that to loose i convenience points we can say (i-2) + 2 or (i-1) + 1 , this is the maximum sum achieved at (i-2) points + add the highest important application which is available or maximum sum achieved at (i-1) points + add the highest regualar application which is available . this is how i made the transitions , along with this i also stored the index upto which regular and important applications were used . it was o(n)
 » 16 months ago, # |   0 What will be the time complexity of last question??
•  » » 16 months ago, # ^ |   +2 Time complexity of editorial solution for problem G is O(n.log(log(n))). But, you can solve it in O(n.sqrt(n)) by finding factor of every elements in a.
•  » » » 16 months ago, # ^ | ← Rev. 2 →   0 thanks
•  » » » 16 months ago, # ^ |   0 No editorial solution is O(nlogn)
•  » » » 16 months ago, # ^ |   0 I have done with O(n.sqrt(n)) it gives TLE.I think it's because the sum of n is not <=2*(10^5) in this problem.
•  » » 16 months ago, # ^ |   +5 Time complexity will be O(N log N), because, each iteration we were adding N/i where, i is number iterations. In other words, N/1 + N/2 ... N/N ~= N*log(N).
 » 16 months ago, # |   +28 My own set of video solutions, probably with some overcomplications (as usual...)
 » 16 months ago, # |   +1 Check out my explanations of problem F and G — solution
 » 16 months ago, # |   +35 Screencast with narration + Solution Explanations: https://youtu.be/WynaHclse_4
 » 16 months ago, # |   0 How to solve D if conveniences b[i]<=1e5 ?
 » 16 months ago, # |   0 My D is giving runtime error on 2nd case. exit code -12343838 something like this. I tried it for many test cases but it is giving me right output as well as i tried it for some cases which are shown for 2nd test-case also. It is working fine. Can anyone help me? submission: 105393105
•  » » 16 months ago, # ^ |   0 i = (int)ones.size()-1; j = (int)twos.size()-1;
•  » » » 16 months ago, # ^ |   0 thanks a lot. this thing happened with me some time ago also. from now i will everytime use this. x.size() -> (ll)x.size() thanks a lot.
•  » » » 16 months ago, # ^ |   0 Hey can you tell me the issue that happens because it usually works fine with inequalities (i < ones.size) but here in case of the equality it showed this runtime error.
•  » » » » 16 months ago, # ^ |   0 Nevermind Understood through this commentComment
•  » » » 16 months ago, # ^ | ← Rev. 2 →   0 Thanks, my solution had the same problem. What problem occurs if we don't cast to int?
 » 16 months ago, # |   0 Anyone want to increase their hack count??Here you go.... 105318690
 » 16 months ago, # |   0 For problem D, shouldn't 0-1 knapsack work? I did have a feeling that the convenience values of only 1 & 2 were important, but my initial intuition was to simply calculate the maximum convenience for memory up to (total memory of all applications — m). Then, the minimum convenience lost should be (total convenience of all applications — maximum convenience possible). My solution doesn't seem to work, but I am not sure why this solution would not work for all cases.
•  » » 16 months ago, # ^ |   0 It sounds fine to me. Can you point out any case where it doesn't work or any code snippet with WA? I understand it may cause TLE but other than that sounds ok.
•  » » » 16 months ago, # ^ |   0 Ah yes, it turns out I had a bug because I wasn't handling impossible case (-1) properly. Once I fixed that it seems to work, but it is very inefficient, as I am now hitting MLE and TLE as you predicted. I will try to optimize this solution, but I have a feeling I will just end up with the proposed solution in the editorial anyways. Good learning experience nonetheless!
•  » » » » 16 months ago, # ^ |   0 Yes. Knapsack makes sense with smaller constraints over N and M. These constraints don't look like typical knapsack constraints and usually when the problem is constrained in a new way (example each value is 1 or 2), then there is something else that must be taken advantage of.
•  » » » 16 months ago, # ^ |   0 I tried D with priority queues by making different queues more important and less important respectively. But it gave wrong ans with some case.This is my code https://codeforces.com/contest/1475/submission/105424077Any suggestion in code or logic will be helpful.
•  » » » » 16 months ago, # ^ |   0 I made a pair of power and convenience point and sorted it according to convince point but it also gave me the wrong answer.
•  » » 16 months ago, # ^ |   0 thought of the same approach but the constraints of m made me think of something else
 » 16 months ago, # |   0 Can you share with problems like G where was O(N log N) trick?
•  » » 4 months ago, # ^ |   0
 » 16 months ago, # |   0 Why can't we consider a number (say n) as it's own divisor in problem A? I mean a number is surely its own divisor! I don't think the problem setters have accounted for this, or am I missing something?
•  » » 16 months ago, # ^ |   0 There's no restriction like that allowing for prime numbers > 2 to pass
•  » » » 16 months ago, # ^ |   0 I don't understand then why does 105409438 not work. Maybe you can help me realize my error?
•  » » » » 16 months ago, # ^ |   0 It probably has something to do with the following:Precision issuesusing == for comparing doublethe log function probably gives a not so accurate answerTry solving the problem without floats/doubles
•  » » » » » 16 months ago, # ^ |   0 Noted & Thanks!
 » 16 months ago, # |   0 In D why this does not works? Sort the array consistimg of all a[i] ( imp nd regualr both) in inc. order.Select from beginning apps till the sum does not exceeds m. Then try to replace selected important apps by remaining regular apps.
•  » » 16 months ago, # ^ |   0 Does your code work for this example? N=5, M=9A= 5 5 3 3 3 B= 2 2 1 1 1
•  » » » 16 months ago, # ^ |   0 Can you tell how we can solve problem D by sliding window?? i solved it using binary search but want to know how will use sliding window.
•  » » » 16 months ago, # ^ |   0 Thanks got that!
 » 16 months ago, # |   0 Can anybody help me out with the difference between the 2 codes which are almost the same except for the fact in 1st I am directly using vector size and in the second submission I am saving the size in tmp variable and then using it: 105405168 [WA ON TC 7] 105408860 [AC]
•  » » 16 months ago, # ^ |   +1 size() returns an unsigned integer. It can give unusual output in case when size is 0 or in similar cases. So it is better to typecast it. When you stored the value in temp what you did was basically typecasted it to int and it worked fine.
 » 16 months ago, # |   0 As many people are posting solutions on their youtube channel. I would love to see 15 minutes video from top performers like tourist. Hopefully he will add some contest video to his channel soon.
•  » » 16 months ago, # ^ |   +85 Just watch my video on 2x speed.
•  » » » 16 months ago, # ^ |   +1 My first question is hacked by n=1 but in question n>=2. Should I also consider cases which are not in input range
•  » » » 4 months ago, # ^ |   0 I am Following you !! Thank you so much ..!** keep up the good work please ! **
 » 16 months ago, # |   -21 (A+B) VIDEO_EDITORIAL : https://www.youtube.com/watch?v=TSEG-5wYS5w
 » 16 months ago, # |   0 (Regarding Problem C)Why does this TLE?Also, in other sources for the same problem where I use a C-like array instead of std::vector (though this would also apply for std::vector, I think), why is it that occ[2][MAX_NR + 1] is considerably faster than occ[MAX_NR + 1][2] (514 ms. vs. 1357 ms.)? I kind of read about the difference between those two some time ago, but I didn't really remember much.., so it would be great if someone could perhaps give a link explaining this.
•  » » 16 months ago, # ^ |   0 It TLEs because you are trying to allocate MAX_NR length for each test case, and there are 10^4 test cases.
•  » » » 16 months ago, # ^ |   0 Wow, that makes sense. Thanks a lot!
 » 16 months ago, # |   0 I don't quite understand ' if(n & (n — 1))' in the solution to A. I did some research and found that the binary representation of any number that is a power of 2 is 10 to the i and the binary representation of any (power of 2) — 1 is a string of 1's the length of the power of 2 — 1. So performing an AND operation gives a string of 0's in the case that the input is a power of 2 and a string of 1's and 0's in the case that it isn't a power of 2. 1. How can that be used in an if statement? If it's 0's (i.e. the input was a power of 2), is that the equivalent of it being false, and the contrary for a string of 1's and 0's in the case that it isn't a power of 2?
•  » » 16 months ago, # ^ |   +1 Let's say $n$ is a power of $2$. Then, in base $2$, $n$ will look something like:$1000000\cdots000$and $n - 1$ will look something like:$0111111\cdots111$If we bitwise $AND$ these two, we obtain:$1000000\cdots000\space \&$$0111111\cdots111 =$$0000000\cdots000.$Which is equal to the representation of $0$, in base $2$. That is, if $n$ is a power of $2$, $n \space \& \space (n - 1)$ equals $0$. It's not hard to see this equals $0$ only if $n$ is a power of $2$. In all other cases, it will return some nonzero number. In a condition, $0$ evaluates to false, while any nonzero number always evaluates to true. Thus, if (n & (n - 1)) = if (false) when $n$ is a power of $2$, and if (n & (n - 1)) = if (true) when $n$ is not a power of $2$.
•  » » » 16 months ago, # ^ |   0 Thank you for the thorough explanation! That cleared up everything. The reason I was particularly confused was that I didn't know that a binary number like, for example, 01010101110 (binary number after bitwise AND operation with non-base-2 number n and n-1), could be evaluated as true.
•  » » » » 16 months ago, # ^ |   0 Well, every number is represented in binary, internally. So, for example, you can have int x = 9 & (9 - 1); And $x$ will be equal to $8$, because the binary representation of the bitwise $AND$ between $9$ and $9 - 1$ is $1000_2$, which corresponds to the base $10$ number $8_{10}$.
 » 16 months ago, # | ← Rev. 2 →   0 Can anyone tell me what is binpow,bigmod,invfactorial.....(I saw them in some people's code)__ In problem E.I used simplified nCr,but it' giving WA
 » 16 months ago, # |   +1 For problem E, I had a pure DP approach different from the editorial with no use of combinatorics, which I think works (at least I wasn't hacked yet if it wasn't the case).Let's call $dp[i][j]$ the maximum number of followers we can get by choosing $j$ people in a prefix $[0,i]$ (the order of the array doesn't matter). Then let's also have another array $ways[i][j]$ which represents the number of ways to get to the amount of followers indicated by $dp[i][j]$. As a base case, it's easy to see that the maximum number of followers when choosing $0$ people is obviously $0$, and by that reason the number of ways of getting to that result is only $1$, so $dp[i][0] = 0, ways[i][0] = 1$ for all $i$. Then, we can calculate the value for the rest of the states: for each $i$ and $j$, $dp[i][j] = max(dp[i-1][j-1]+followers[j],dp[i-1][j])$. It means that the maximum amount of followers we can get by choosing $j$ people is already the calculated value for $j$ in the previous prefix, or choosing the blogger in position $j$ and adding the corresponding followers to the best way of choosing $j-1$ followers in the previous prefix. And $ways[i][j]$ is set to $ways[i-1][j-1]$ or $ways[i-1][j]$ in the first or second case respectively. Also, if we get to the case where $dp[i-1][j-1]+followers[j]$ is equal to $dp[i][j]$, then we add the corresponding ways from $ways[i-1][j-1]$ to $ways[i][j]$, applying $\%MOD$ to avoid overflow. Just to be clear, I changed a little bit the wording from what I really implemented so it was easier to explain, but the idea is very similar. Here's the submission: 105415244
•  » » 16 months ago, # ^ |   0 I had the exact same solution.
 » 16 months ago, # | ← Rev. 2 →   +3 IMO easier solution for B: make a bool array DP length of the maximum possible n(1e6, as I remember) and fill it with false. Then make dp[2020]=dp[2021]=true. And for each number in [4040, 1e6] if dp[i — 2020] or dp[i — 2021] is true, than dp[i] = true. This basically means “if it is possible to reach B”. And then for each test case just print dp[n] ? Yes : No!
 » 16 months ago, # |   0 Anyone stuck at D , can watch this https://youtu.be/c7h4hUdXX1E
 » 16 months ago, # | ← Rev. 2 →   0 Hello I use greedy to solve problem D :) if max1_type2 > max1_type1 + max2_type1: choose max1_type2 else choose max1_type1 you can see my code here : https://codeforces.com/contest/1475/submission/105374802
•  » » 16 months ago, # ^ |   0 My approach was quiet similiar , but I popped two elements of 1 priority (when sum of these two was greater than the sum of priority 2 single element) , couldn't figure out whats wrong in this approach , can you help me ? This is my solution : https://codeforces.com/contest/1475/submission/105392908
•  » » » 16 months ago, # ^ | ← Rev. 2 →   +3 I try hard to find your mistake if x > y: m -= x1; q1.push(x2); q2.push(y1); else . . . for sample input: 4 12 4 4 4 1 1 2 2 1 your ans will be 6 but my ans is 5
•  » » » » 16 months ago, # ^ |   0 Thanks a lot , can you teach me how to find these test cases by yourself.
•  » » » » » 16 months ago, # ^ |   0 Actually I guess ! because you pick up 2 elements each time but think about this input # inf 1e15 3 inf+2 inf inf 1 1 2 1 your program picks up element 1, 3 I think. but it's not necessary to pick up element 3, greedy Guarantees that max1_type1 is best at a time or max1_type2 and not about any other element.
•  » » » » » » 16 months ago, # ^ | ← Rev. 2 →   0 solutionhere i sorted sorted according to minimum point with maximum loss and sorted according to maximum loss with minimum point using 2 priority queues and took minimum of them bt gave me WA :( any help will be appriciated.thanks
•  » » 16 months ago, # ^ |   0 Hey,I tried D with priority queues by making different queues more important and less important respectively. But it gave wrong ans with some case.This is my code https://codeforces.com/contest/1475/submission/105424077Any suggestion in code or logic will be helpful.
•  » » » 16 months ago, # ^ |   0 you can find your bug with this.
•  » » » » 16 months ago, # ^ | ← Rev. 2 →   +1 Actually the input you given is wrong it should be :-4 124 4 4 11 2 2 1and i am getting correct output for this.
•  » » » » » 16 months ago, # ^ |   0 I edit it, thank. I do many tests but I can't find your bug :(
•  » » » » » » 16 months ago, # ^ |   +1 I got my error buddy here https://codeforces.com/blog/entry/87188?#comment-753549
 » 16 months ago, # |   0 Thanks for contest, I thought D, F and G were very nice problems for beginners.
 » 16 months ago, # |   0 Another solution for B that is simpler I guess is to notice that (2021 — 2020 = 1) as U can make any number using only (1's), U can take as much as possible of 2020, if after that (n) equals to (2020 * taken_count), that's the answer, else I just check if the remaining is less than or equal to the count of (2020's) I've already taken to check if I can fill the missing value with (1's) (Simple enough ^^) int taken = n / 2020, remaining = n % 2020; cout << ((remaining <= taken)? "YES" : "NO") << endl; 
•  » » 16 months ago, # ^ |   0 I knew it had to be simple, why do editorial providers on codeforces insist on making editorials extremely hard. This was simple!
•  » » 5 months ago, # ^ |   0 That was really the most simple solution. Taking that assumption "I guess is to notice that (2021 — 2020 = 1)" made my mind. Thank you. Also, considering for each test case this solution takes O(1) to output an answer, it is pretty much as fast as the editorial proposed solution.
 » 16 months ago, # | ← Rev. 2 →   0 Can anyone share a more formal proof of F? Why are 2 cases handled in the solution? What is this 'times' variable?Here is my current algorithm with logic: We have 2*N control variables: The flip of each row, and flip of each column. Each variable can be 0 or 1 (as the order doesn't matter) Elements in first row are determined only by the flip of 1st row and flip of all columns. So we look at all possible cases for this that can make first row of A equal to B. We do this for 2 cases: one where first row of A is flipped, one where it isn't. (note that the columns flipped in 2 cases will be complement of each other) Now, the flip or not of each column is fixed based on step 2. So only remaining variable is flip of each row other than 1st row. We can decide flip of each row by looking at first element in the row. Now all our variables are determined. At this point, A must equal B if the solution exists, in at least 1 of the 2 cases. But do we need to check both cases? In case 2, the flip of each row and column will be opposite to the flip of each row and column in case 1. Therefore for each(Row,column) pair (i,e. cell). The result will be the same in either case. Therefore, it suffices to check only 1 case. I follow this deterministic setup: where i first set first row of A as same of B by flipping columns (selecting the case where first row doesn't need flip). Then.I set first column of A as same of B by flipping rows. Then I check the other elements. Based on arguments in 1-4, this is sufficient. Please help if I am overcomplicating this and there is a simpler understanding.
•  » » 16 months ago, # ^ |   0 Sorry for that I will not answer your post, instead I'll describe my solution, because I don't understand editorial.You should know from properties of XOR order does not matter, so we can reorder all operations into: perform all XORs of rows, and then all XORs of columns. Now, if any of operations is done twice then you can do nothing instead. Therefore you need to know for each of row and column do you need to perform corresponding XOR or not.For any cell in matrix after all XORs performed value will be changed or not. So, you can make matrix of "should I change value or not" — this is actually XOR of both matrices. You could also came up with this idea if you think of question "with what I should XOR to get from matrix A get matrix B?" Let's call this matrix C! So, C = A XOR B. Also C is "what cells should I flip?". This leads us to following equal problem: if you can make C matrix from zeroes matrix, then you can make B matrix from A matrix.How to figure out can we make C matrix from zeroes? Well... Let's split into two cases. Case 0: we don't need to XOR first row, then 0 and 1 in this row tells us: should we invert column or not. If any other row is same (identical, all 0 and 1 match first row) then after performing all columns XORs we get all we need. Otherwise, to be able to make it from zeroes, the only chance we have is to perform XOR of those rows, and to be able to make them they should look like our first row inverted.Case 1: we need to XOR first row, then 0 will tell that we should invert this column, and 1 tell us to not invert. And similarly, if we see same row somewhere else, then we just perform XOR of row and after all XORs of columns we get what we need. And for other rows, the only chance to make them is to NOT invert them, this means they should look like our firs row inverted.In both cases all rows of matrix C should consist of row 1 and inverted row 1. Therefore, solution is following: make matrix C, check that all rows is either identical to row 1 or identical to inversion of row 1.
•  » » » 16 months ago, # ^ |   0 Thank you very much. I understand much more clearly now
•  » » » » 15 months ago, # ^ |   0 I have a very simple solution, got idea from comment section itself-one observation is that we can't apply same operation multiple time in a row or column. So basically we can fix one row/column(let's say row 0) and will check one time by taking XOR of this row and second time without taking XOR. Here is implementation — https://codeforces.com/contest/1475/submission/107153476
 » 16 months ago, # |   +3 Thanks to Stepavly and Supermagzzz. The contest went well, but unfortunately, it was delayed.
 » 16 months ago, # |   0 Can anyone Please help me,why I'm getting WA in problem c In case 3:( i think my idea is totally fine :)105363911
•  » » 16 months ago, # ^ |   0 Almost similar solution ig you have done some mistake while getting proper count https://codeforces.com/contest/1475/submission/105350366
•  » » » 16 months ago, # ^ | ← Rev. 2 →   0 got it :) but can you prove that(ans+ (k-a)- b +c ) != (ans+ (k-(a + b — c)))
•  » » » 16 months ago, # ^ | ← Rev. 2 →   0 again WA but why?105436588
 » 16 months ago, # |   0 For Problem G,why let the $\mathcal{O(\sqrt{n})}$ finding divisors algorithm pass!!!
 » 16 months ago, # | ← Rev. 2 →   0 For problem G, can someone please explain why is it incorrect to calculate dp in reverse. Why dp[i]=max(dp[i], cnt[i]+dp[i*j]) where i*j < 2e5 wrong? 105437344
•  » » 16 months ago, # ^ | ← Rev. 2 →   0 1 1 200000 You might get a TLE anyways.
•  » » » 16 months ago, # ^ |   0 Thanks for pointing out the bug. Complexity is O(NlogN), so didn't get TLE. Accepted solution: 105442203 (doesn't require the extra step of applying sieve)
 » 16 months ago, # | ← Rev. 2 →   0 Hi everyone can anyone please suggest why this solution is not passing all the testcases. My idea is to use log aprroach---> z=log2(x) if z is an integer then the x is power of 2 else it must contain an odd number as is its divisor. for example if z is = 3.22.. then z is not exactly a multiple of 2 if z is = 3 the z is exactly a multiple of 2 My soultion get failed on test case 2 (8029th token) code link : — > https://codeforces.com/contest/1475/submission/105435613 Thanks for your help
•  » » 16 months ago, # ^ |   0 You can refer this which clarifies that using log is somewhat inaccurate:https://stackoverflow.com/questions/57025836/how-to-check-if-a-given-number-is-a-power-of-two
•  » » » 16 months ago, # ^ |   0 Thanks a lot future_me. One of the youtuber actually sent me link https://floating-point-gui.de/ which gives a breif idea why my solution doesnt work on large no's.
 » 16 months ago, # |   0 Why I get 'uninitialized value usage' error https://codeforces.com/contest/1475/submission/105439474?
•  » » 16 months ago, # ^ | ← Rev. 2 →   0 Faced same issue, just move your variables declarations in global scope, outside of solve method.Since there can be many test cases, you cannot use memory for each one. For reference (declarations outside of test cases loop): https://codeforces.com/contest/1475/submission/105419352
•  » » » 16 months ago, # ^ |   0 I face the same problem. https://codeforces.com/contest/1475/submission/105442011
•  » » » » 16 months ago, # ^ |   0 your submission with other arrays declared outside of loop too:https://codeforces.com/contest/1475/submission/105443143
•  » » » » » 16 months ago, # ^ |   0 Thanks a lot.
 » 16 months ago, # |   0 Usually I won't touch E, but this Problem E was pretty easy in this way..https://codeforces.com/contest/1475/submission/105444607
 » 16 months ago, # |   0 Your text to link here... Problem E
 » 16 months ago, # |   0 Hello everyone i just want to share my approach for problem C. I used maps to solve this problem. I stored the frequency of boys and girls and also pair of a boy and girl. Now if we want to calculate how many other couple can go with current couple. Say a is boy and b is girl we have in current couple. Then the number of couple that can go with a and b are Total couple-frequency of a in boys -frequency of b in girls + frequency of pair a, b. And do this for all couple and just divide the answer by 2 because we will count every couple 2 times. 105342359 Check this submission.
 » 16 months ago, # |   0 105451015 I am unable to figure out what is wrong with my submission please help
 » 16 months ago, # |   0 I just finished my virtual for the contest. I was analyzing my solution for F and found a mistake. But that code had already passed system tests.105447780The mistake I found is that I have done this operation:(1<<1000).This operation is not practically correct but somehow is giving correct result.I think the System Tests are weak coz this solution should not have passed.
 » 16 months ago, # | ← Rev. 3 →   +3 I'd like to propose a super simple solution for F. Just scan every 2x2 square and count the number of difference in A matrix and B matrix in matching positions, if there exist a 2x2 square in which the count of different numbers is 1 or 3, output NO, otherwise output YES. I got AC but hasn't been able to prove why. I just feel like different numbers can never come in a single square surrounded by same numbers or create an L shape. Here is my solution, who can prove why this is correct? https://codeforces.com/contest/1475/submission/105455476
 » 16 months ago, # |   0 I tried D with priority queues by making different queues more important and less important respectively. But it gave wrong ans with some case.This is my code https://codeforces.com/contest/1475/submission/105424077Any suggestion in code or logic will be helpful.
 » 16 months ago, # |   0 (A+B) VIDEO_EDITORIAL : https://www.youtube.com/watch?v=TSEG-5wYS5w
 » 16 months ago, # |   -6 if anyone is still struggling with the problems, here is the video solutions to the last 5 problems. Primarily hinglish for now. Do let me know if this was helpful for you! Thankyou!CODEFORCES ROUND 697Problem C — https://youtu.be/kflXYDwum4k Problem D — https://youtu.be/oroRk1Ev5yY Problem E — https://youtu.be/dd0EOuUIYOQ Problem F — https://youtu.be/wjQknVeioec Problem G — https://youtu.be/UZjTR_NJEZ4
 » 16 months ago, # |   0 For problem G, why can't we replace the N with max element in array a(for each test case)?
•  » » 16 months ago, # ^ |   +1 actually we can.
•  » » » 16 months ago, # ^ | ← Rev. 4 →   0 I tried doing that but I'm getting wrong answer(for sample test cases as well).https://codeforces.com/contest/1475/submission/105476589 gets accepted whereas https://codeforces.com/contest/1475/submission/105476674 gets WA on test case 1 itself.PS: Not my original solution. Even for the official solution, changing m to max(array) gives WA.
•  » » » » 16 months ago, # ^ | ← Rev. 2 →   0 changing m to max(array) in official code gives ac. I don't know what you are doing, but instead of blindly copying the code, try to understand how to solve the problem.
•  » » » » » 16 months ago, # ^ | ← Rev. 2 →   0 I understood how to solve except for the "m part"(only over here did I differ from the original solution when trying to code it out myself). I found the approach in the solution I linked (it's from Neal's stream) slightly easier to understand and more natural than the official solution.https://codeforces.com/contest/1475/submission/105485752 I'm getting WA on changing value of m in the official solution too. Any idea why?
•  » » » » » » 16 months ago, # ^ |   0 idk python well, so i cannot see what's wrong in your submission.
•  » » » » » » 14 months ago, # ^ |   0 replace m by m + 1
 » 16 months ago, # | ← Rev. 3 →   0 Comment Retracted
 » 16 months ago, # |   0 can any one tell why this method is giving TLE: Problem E: https://codeforces.com/contest/1475/submission/105468999
 » 16 months ago, # |   0 I am new to cp, in the problem 3 I was able to follow the editorial to the very end but I didn't get why we are printing ans/2 instead of ans
•  » » 16 months ago, # ^ |   0 we are counting each pair twice. We are fixing one pair and seeing all possibilities of second pair. But this first pair will also be counting again when its corresponding second pair is fixed.If you are doing a different solution where you are counting each pair only once, then you don't need to divide by 2
•  » » » 16 months ago, # ^ |   0 thank u :)
 » 16 months ago, # | ← Rev. 3 →   0 For Problem C, What is wrong with this Solution? I stored the number of times a particular boy or girl is present in more than one pair and calulate the invalid group of pairs. For Ex- If a 'b' boy is present in n pairs, then invalid group of pairs is going to be (n*(n-1))/2
•  » » 16 months ago, # ^ |   0 ll((boys[i] * (boys[i] — 1)) / 2) here (boys[i] * (boys[i] — 1) cause integer overflow . You should replace it by (ll(boys[i]) * (boys[i] — 1)). same for ll((girls[i] * (girls[i] — 1)) / 2)
•  » » » 16 months ago, # ^ |   0 What is the problem with this code?https://codeforces.com/contest/1475/submission/105668864
•  » » » » 16 months ago, # ^ |   0 i think you shouold use array not vector for frequency.
•  » » » » » 16 months ago, # ^ |   0 but still the logic is same then also its saying TLE
•  » » » » » » 16 months ago, # ^ |   0 Give me submission link :)
•  » » » » » » » 16 months ago, # ^ |   0 its already there https://codeforces.com/contest/1475/submission/105668864
•  » » » » » » » » 16 months ago, # ^ |   0 I told you for using array..but still you'r using vector :+0
•  » » » » » » » » » 16 months ago, # ^ |   0 it got accepted after using map. you were right that because of too much memory it was getting TLE.
•  » » 16 months ago, # ^ |   0 I think you are doing mistake in typecasting do it inside the brackets((ll)k*(k-1)/2) simlarly for others..
 » 16 months ago, # |   +3 O(1) solution for Problem BLink to the solution
 » 16 months ago, # | ← Rev. 2 →   0 Damnn, Quesion D was really-really fun :D, learned a lot from it, very very thankful to the problem setters...
 » 16 months ago, # |   0 please someone help, from last 2 months i started codeforces and i am not able to improve my performance yet i am a on a beginner level, I think the problems on codeforces are on little mathematics side. can anyonle please help me , and suggest me some resources for solving mathematical problems.
•  » » 16 months ago, # ^ |   0 just do div.2 a,b,c from last rounds, which most of them are based mainly on maths. If you don't know how to solve the problem, look on a editorial, and try to get an intuition what you've missed before and why you haven't solved this specific problem.
•  » » » 16 months ago, # ^ |   0 ya, i m trying to solve a2oj ladder.
•  » » » 15 months ago, # ^ |   0 if I fail to understand the editorial, then what should I do?
•  » » » » 15 months ago, # ^ |   0 come to this problem later. (it means that the gap is too huge)
•  » » 16 months ago, # ^ |   0 What about codeforces?https://codeforces.com/problemset?order=BY_RATING_ASC&tags=math
 » 16 months ago, # | ← Rev. 2 →   0 problem B had a much simple solution. my solution: 105333636Approach: Let N be the given number and X be N modulo 2020. if X is 0 then we can say that N was sum of certain number of 2020 and if X is not 0 then we check whether X is less than or equal N/2020 if it is then we can put a combination 2020 and 2021.
 » 16 months ago, # |   0 I am getting WA in fourth question, my approach is almost exactly as shown in this editorial code.Can someone tell me where I am wrong? https://codeforces.com/contest/1475/submission/105487065
 » 16 months ago, # |   +9 Editorial for 1475G - Strange Beauty is masterpiece of utterly bad editorial. Why? dp[x] is following. Here is formula. No explanations at all, why there would be numbers like that, why they indeed pairwise ok and so on.
 » 16 months ago, # |   0 How i can solve the problem D use DP !!
 » 16 months ago, # |   0 Can anyone Please explain how to solve E using Dp . :)
 » 16 months ago, # |   0 Ez B ll q; cin>>q; (q%2020<=q/2020)?cout<<"YES\n":cout<<"NO\n"; 
 » 16 months ago, # |   0 In problem D, I used prefix sum + binary search and got AC, Can anyone share DP approach of problem D??
 » 16 months ago, # | ← Rev. 2 →   0 Video tutorials
 » 16 months ago, # |   0 Can someone help me understand why I got TLE?contest : Codeforces Round #697 (Div. 3) problem : C. Ball in Berland problem link : https://codeforces.com/contest/1475/problem/CTLE solution : https://codeforces.com/contest/1475/submission/105347180I resubmit same code. But I got AC AC solution : https://codeforces.com/contest/1475/submission/105608300Why did this happen?
•  » » 16 months ago, # ^ | ← Rev. 2 →   0 [Deleted]
 » 16 months ago, # |   0 I solved B using this logic :Ans = (n/2020 >= n%2020)? Basically, if this is the case, I can replace reqd no. of 2020s with 2121s.Accepted solution.Any issues in this approach ?
•  » » 15 months ago, # ^ |   0 Absolutely correct
 » 16 months ago, # |   0 What does it mean to block edges in a graph?
 » 16 months ago, # |   0 In Problem D how the editorial solution will work for test case a=[5 3 2 1 4] and b=[1 1 1 2 1] and m=7 the answer should be 5+2=7 and we lose 2 convinience points.
 » 16 months ago, # |   0 In problem C, I'm getting a TLE on test case 2 in this solution. Can anyone please help me?? #include #define ll long long int #define REP(i,x,y) for(long long i=x;i>t; while(t--) { ll a,b,k; cin>>a>>b>>k; ll n=a+b; vector u(N); vector v(N); vector sz(N,0); REP(i,1,k+1) { cin>>u[i]; sz[u[i]]++; } REP(i,1,k+1) { cin>>v[i]; sz[v[i]+a]++; } ll ans=0; REP(i,1,k+1) { ans+= k - sz[u[i]] - sz[v[i]+a] + 1; } cout<
 » 16 months ago, # |   0 Can someone tell me what is the problem in my code because it was saying TLE on test case #2. Here is my code
 » 16 months ago, # |   0 How to approach problem D using DP ?
 » 16 months ago, # |   0 Stepavly In the problem C why did you first decrement the x and y and then increment a and b
•  » » 16 months ago, # ^ |   0 Decrement to make indexing from zero, increment to count degree of the vertices.
 » 15 months ago, # |   0 in E , i am having trouble while taking modwhen i submitted without taking mod while calculating factorial then i got overflow. 106346070but when i changed and gave mod while calculating factorial itself then , i got the answer as 0 106343305pls someone help me out.
•  » » 15 months ago, # ^ |   0 division doesnt work well with modulo operator, you have to use the modulo inverse instead. tho you could build pascals triangle instead, its a much simpler approach than calculating modulo inverses
•  » » » 15 months ago, # ^ |   0 oh thanks. I would try that up
 » 15 months ago, # | ← Rev. 2 →   0 for problem F, i found a different solution, however i am unable to prove why this solution must be true.notice that for each n x n matrix, if we take the matrix of differences (if a[i][j] != b[i][j] for all i and j) each 2 x 2 matrix contained within it can always also be created from a zero 2 x 2 matrix using the two operations given.for example: 1 1 0 0 0 1 1 1 0 contains: 1 1 0 0 1 0 0 1 0 0 1 1 0 1 1 0 these are all possible to create using the vertical and horizontal xor operations from an empty 2 x 2 matrix. you can check them yourself.so the solution is to check each 2 x 2 matrix for this rule, and if they all work, the answer will be YES, otherwise NO.however, i was not able to prove why this always works out. could anyone prove this? my solution: here
 » 15 months ago, # | ← Rev. 2 →   0 I tried D using DP but getting MLE, It passes all test cases but fails on large input value https://codeforces.com/contest/1475/submission/107084258 Any solution??
•  » » 15 months ago, # ^ |   0 M goes upto 10^9, you cant use that much memory.
»
15 months ago, # |
0

I feel problem-B more easier to use these codes.

# include<bits/stdc++.h>

using namespace std; int main(){ int n; cin>>n; while(n--){ int k; cin>>k; int s; s=k/2020; if(k>=s*2020&&k<=s*2021)cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }

 » 14 months ago, # |   0 After one whole day working on Problem D, reading the Editorial and some relevant comments, and finally realise the input for b is either 1 or 2...
 » 13 months ago, # |   0 Stepavly I think I've found a simpler solution for problem B. I would appreciate if you could check it out and see if there are any problems: 110736225 Thanks! :D
 » 11 months ago, # | ← Rev. 2 →   0 699
 » 9 months ago, # |   0 if any one asking about dynamic programming solution for problem B so just thinking like coin change problem but you will take 2020 and 2021 as coins then make dp [0][maximum_sum] where maximum sum here is 1e5 after making dp with maximum number so we can answer queries in o(1) because of perprocessing of dp[0][1e5] if you still feel confused so just take a look in my code:https://codeforces.com/contest/1475/submission/124968035
 » 8 months ago, # |   0 Problem C got a 100% binary search solution: 128061064 Idea: sort by boys increasing. Binary search to find first boy has larger value than the current boy. Then binary search again to find the number of boys paired with the current girl (by storing the position of all boys paired for any girl). Then add up.