I did the very same thing, in Java, got TLE: CodeChef: Practical coding for everyone
I guess Java performs poorer, despite that the time threshold is increased for it.
I did the very same thing, in Java, got TLE: CodeChef: Practical coding for everyone
I guess Java performs poorer, despite that the time threshold is increased for it.
thanks bro
very nice problem !!
thanks!!
Nice problem. Setter’s implementation is clever. I had to group coordinates twice because of not using pair for mapping. And I thought about selecting the median, but I wasn’t sure about this. Luckily I found out that the cost function is uni-modal. So I used ternary search to find the number of moves.
and for this all kind of modular arithmetic i made some functions so that in contest time , at least these type of error will not happen -
ll modmul(ll a, ll b) {
return ((a%mod) * (b%mod)) % mod;
}
ll modadd(ll a , ll b){
return((a%mod)+(b%mod)+mod)%mod;
}
ll modsub(ll a , ll b){
return((a%mod) - (b%mod) + mod)%mod;
}
I knew how to deal with mod on negative numbers but still got WA.I didn’t read the constraints that the co-ordinates could be negative.
Code which got WA on 47th minute of the contest
AC code
Both of them differ only in line 62.
Goodbye, 5 stars dream!
Goodbye, 5 stars dream!
Why?! Come on, just see how fluctuating my rating is! That’s because I never guard it as a treasure, and always participate, so that I can learn new things. And that’s why I have been destroying it dozens of times. I used to be 5 stars once.
Of course your dream is not gone. One day it will happen. Believe in yourself!
Come here any time a contest takes place, and learn new stuff.
Also, see my Java code, it does exactly what the editorial says, but it gets TLE. What should I say?
It is not fair to get advantage only because your language of choice is C/C++. But this is life. It is hard-to-impossible to say simply that JavaLimit = 2*CLimit.
I think the problem statement states that c > 0. Hence the answer should be no.
Ahh yeah …even I did same mistake 
Can someone help me find the bug in my solution? Here it is. I am doing exactly like the editorial states.
Yeah, you get so used to positive-only questions that you don’t even notice when they can be negative. Anyway, don’t you think it is nice to know that you knew everything you needed to solve the problem. I think that’s far more important than handing in an AC solution in time.
can you explain more about mistake @priyansh19077
here is my solution…please look at this too
https://www.codechef.com/viewsolution/34624892
Nice Idea, I have added a new snippet with this to sublime text
I have also added modpow and modinv for the modular power function and the modular inverse. On top of that I have added some inline variants.
I might actually turn it into a class with operator+, operator-, operator*, operator/ to allow calculations as normal and handle modular arithmetic in the background. And then of course turn that class into a snippet.
nvm, figured it out. I was calculating mod 2c instead of just c. Still gives errors. Here is the updated code
I agree, it’s great to see that I got all the right ideas in my head, 100%. Much more important than the AC.
try out the case when you have the numbers 1, 5, 17. If you find out the average for this it will be (1+5+17)/3 which will not be an integer. Now, if you talk about the average element that can be integer, then you can consider it like this. suppose 1 is the 1st term in the AP, then 17 will be the 5th term in this AP. So by this if you take the 3rd term as the average it will be 9. The number of moves for 9 will be (9-1)/4 + (9-5)/4 + (17-9)/4 = 5
Now, if you take the median element which is 5, the answer will be (5-1)/4 + (5-5)/4 + (17-5)/4 = 4
So, clearly taking the median element and not the average in any way can get you the right answer. I was doing the same mistake during the contest but realized it only after reading the editorial.
Sure.
can somebody help me find the issue . I coded this after reading the editorial because i could not solve it during the contest. seems like i couldn’t solve even after reading the editorial.
https://www.codechef.com/viewsolution/34633642