Himitsu's blog

By Himitsu, history, 4 weeks ago, In English,

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://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

 
 
 
 
  • Vote: I like it  
  • -11
  • Vote: I do not like it  

»
4 weeks ago, # |
  Vote: I like it -12 Vote: I do not like it

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?

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it +15 Vote: I do not like it

    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.

    • »
      »
      »
      4 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I understand, typecasting to signed integer will help me to notice these type of errors. Thank you for the explanation and going out of your way to compile my code on your system.

      Thanks a lot!