16204's blog

By 16204, 3 years ago, In English

(Feeling excessively confused, might delete later.)

So I admit I'm not exactly a computer specialist myself. But today after spending a large amount of time trying to optimize the solution for a problem, I came across this gem:

Okay, two submissions with one taking 2x time as the other. Must've been a terrible attempt at optimization which actually significantly increases the amount of operations, or somehow restructure the order of operations so the computer can't optimize them. Uh huh. Yeah sure. That would've been my thoughts, if this isn't what I added to the second submission:

Unless there is higher forces at play trying to botch my submission, I suspect that there must be some problem with the judge (or maybe I just don't understand how it works). While of course I'm not exactly sure what is happening, I think that adding a variable and increases it by one should not take up to 2000ms, and as such, this warrant some investigation.

(In case anybody wants to go and investigate this yourself, comment and I'll post the submissions and problem link on Ideone.)

  • Vote: I like it
  • +162
  • Vote: I do not like it

»
3 years ago, # |
  Vote: I like it +26 Vote: I do not like it

The line is undefined behavior. The compiler is allowed to do anything in these cases.

  • »
    »
    3 years ago, # ^ |
    Rev. 2   Vote: I like it +27 Vote: I do not like it

    Huh, interesting! But when I change the line to "ll rnd = 0", it still takes 3931ms. Better, but definitely not by enough.

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it +5 Vote: I do not like it

      Okay that's really interesting. I would recommend you to share your code. I remember a case once where there were a pair of solutions getting AC and WA with the difference being an empty newline. It arose because of undefined behavior somewhere in the code.

»
3 years ago, # |
  Vote: I like it +19 Vote: I do not like it

It must be a supercalifragilisticexpialidocious problem.

»
3 years ago, # |
  Vote: I like it +34 Vote: I do not like it

time to add this to my template