david_varela's blog

By david_varela, history, 6 years ago, In English

Hi everybody,

I discovered that different submissions with exactly the same Python code obtain different results (accepted, TLE).

I also realized that the individual tests differ in memory and time, where recent executions (August 2018) use less memory but need more time.

  • Problem 222b, submission 33921342, test 1 requires Time: 60 ms, memory: 5428 KB
  • Problem 222b, submission 42010082, test 1 requires Time: 216 ms, memory: 0 KB

Some ideas about the possible reasons? I can only think in different sub-versions of Python 3, something else? Any solution from the dev(participant) side? Change the language is the only one I can think by now...

Thanks for your help and happy coding.

David.

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

»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by david_varela (previous revision, new revision, compare).

»
6 years ago, # |
  Vote: I like it -20 Vote: I do not like it

LoOoOooL. LMAO. Another redundant question. This has been asked many times on CF. The answer is always the same — you just got lucky to get AC and server fluctuation is the culprit.

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

    Thanks for the explanation. I didn't find the question asked before, although it's not easy with the blogs system. I thought that the submissions were executed in some kind of isolated environment with guaranteed resources.

    The server explanation would affect the processor time for the submissions, however, the used memory also differs. If the submissions have the same code, they will allocate the same memory if the python versions are the same, don't they?

    ps: for your information, I consider the sentence "LoOoOooL. LMAO. Another redundant question." a bit rude.

    • »
      »
      »
      6 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      it's not the same submission, you imported math in the second one, which did not occur in the first one. Maybe this causes increased memory usage.

      Plus, your first example was literally 6 ms from tle. Everything looks normal to me

      • »
        »
        »
        »
        6 years ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

        Hi farmersrice, thanks for answering.

        In the first pair of submissions, the ones for the problem 222b (33921342 and 42010082), the code is exactly the same, and the difference with the memory happened too.

        In the second pair (problem 372a), as you said, I removed (42224415) the import due to a warning on the editor, and it could explain the difference in memory so, for testing purposes, I tried it again copying the exact same code as in the accepted submission (37037681) including the import of math. The result is in the submission 42248709, where the difference of memory usage persists. Importing math the memory is also 0 in tests 1 t0 8, while in the accepted submission there is at least 6800k of memory used on each test case.

        I don't know if the acceptance or not of the submissions are related to the difference of usage of memory, but to me looks like recent submissions use less memory and need more time, for the same code.

        • »
          »
          »
          »
          »
          6 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Interesting. All I can say is that python isn't a good choice for competitive programming.

          • »
            »
            »
            »
            »
            »
            6 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            I know, I'm starting to write in C++ some problems with time constraints for the correct logic.

            For future readers and Python coders, I could submit accepted solutions for the mentioned problems changing to Python2, but not with PyPy3.

        • »
          »
          »
          »
          »
          6 years ago, # ^ |
          Rev. 4   Vote: I like it 0 Vote: I do not like it

          the running time for the same code will not always be the same, there will be some error. since your running time is very close to the limit, it is natural that you will TLE. As shown 42261507 and 42261531, they TLE at different area with the exact same code. (though the slow down(if there was any) might have something to do w intel's bug, I've not been following the recent updates)

          As for why the memory is different, this is due to you failing on different testcase, and therefore the memory used in different test is different.

          • »
            »
            »
            »
            »
            »
            6 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Thank you so much for the time you dedicated to creating new submissions. I could check in your submissions that the memory differs in individual tests for the same code, very interesting! I expected the global memory to be different because the amount of test executed is also different, however different memory usages in the same test with the same code is a surprise! If the memory varies from submission to submission (although I don't understand why) both, the memory difference and the time difference make sense now :)

            As a curiosity, in the old submissions that I checked the memory for the first cases was never 0kb, but something common in recent submissions, where for shorts tests the memory used is 0kb.