Hey codeforces, I have two issues and I need your help in them :
Last round Codeforces Round #287 (Div. 2) I faced such an odd issue, I solve the first problem and I submit it, luckily my code has passed the pretests, then during the system test my code failed at case 30, since the problem A was such an easy, unmistakable problem, I opened the test cases to see where did my code fail, I found that, my code print a 67 elements which actually more than the whole input (whereas the problem was to select some elements from input) . I work on Code::Blocks IDE, which has
g++
compiler, and submit my code atGNU G++ 4.9.2
compiler on codeforces as I always do, I revised my code, and make sure it's totally correct, I tried to submit it again atMicrosoft visual C++ 2010
, and it got AC . Could anyone explain what happened ?I tried to solve B. DZY Loves Chemistry and almost I have the same problem above, my computer correctly produces answers and I got WA on test 4, here is my submission . I debugged my code and checked the array each step I modified it, and all went right, I tried to submit it at another compiler but it still gets WA on test 4, I roughly made sure that, my algorithm/code were absolutely right, but couldn't realize why that happens
Any tips, tricks, and notes would be appreciated, and I'd be so grateful if someone elaborates what exactly happens to evade it in the next times. Thanks in advance codeforces :")
(sorry for bothering but I don't post this, till I ran out of my all attempts to figure out what's going on in these issues)
in your submission 9519933
your mistake in this line:
while(res < k || cnt < (n-1))
because when the value of k is very big the condition inside while is always true so it will not end the while expect when a 'break' command is called , and the only 'break' command you have is in this conditionif(res + ins[cnt].first > k) break;
but as I assumed earlier k is very big so this condition is always false , but whencnt
comes out of bound the expressionins[cnt].first
will have random values depending on these values the while might end after adding some random values to the output so the correct line iswhile(res < k && cnt < n)
Why did this code get AC on other compliers? it depends on the values that the expression
ins[cnt].first
haveIn the second submission, function fSet doesn't return any value in case when dSet[i] ≠ i. Consider enabling all the compiler warnings in your IDE. Read this for more information about g++ warnings.