Hello,
I am solving this question and it is failing in test case-3.
The test case is as follows:
8 2
Link to submission: http://mirror.codeforces.com/contest/1072/submission/44671042
Output on my terminal(on running the same code) is coming as the correct answer but judge is showing some other output.
I have no idea why this is happening. Can someone help? Thank You
I don't mind the downvotes but can someone atleast tell me what I am doing wrong? or is downvoting without any reason the only thing you people(to the downvoters of this blog) are good at?
Main issue is the size of ar — in that testcase, it's 1, and ar.size()-2 as an unsigned integer is something very large — much larger than the size of your vector (ar.size() is unsigned). In general, if you really need to use something.size(), I suggest typecasting it to a signed integer first, to avoid stuff like this happening.
As for why it works locally, look at your compiler settings — those are most likely different from what is being used on the judging server. When I compile your code, for example, I get several warning messages from your macros about comparisons between signed and unsigned integer expressions.
I hope this helps others who face the same problem, the reason is similar. For one of my submissions, I had signed integers in all places but was accessing it with negative index which threw the same error. I did no bounds checking while using std::vector::operator[] and ended up treating memory I don't own.
Credit: https://stackoverflow.com/questions/50844864/runtime-error-addition-of-unsigned-offset-to-0x129000a0-overflowed-to-0x1290008
LoOoooLoOoOooooLoOoOoOooOooOL. ROFL. LMAO. Are you sure you are even a C++ programmer? Or are you just a code monkey? Maybe there is a ghost in your/codeforces compiler after all. XD.
Looks like that you're out of blogs to spam on. This one is from 7 weeks ago XD