inbarin's blog

By inbarin, history, 5 years ago, In English

as I submitted my code to D (1 or 2, doesn't matter) it had TLE at test 2. https://codeforces.me/contest/1326/submission/73715713 I reshuffled the code and it passed. https://codeforces.me/contest/1326/submission/73724920 now the weird thing is that my original code passed test 2 when I ran it from home. any ideas why or what?

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

»
5 years ago, # |
  Vote: I like it +35 Vote: I do not like it

Reason: Line 469, you used the macro

fortob(0, extra.size())

Which, from line 23, is equivalent to

fornb(j, 0, extra.size())

Which, from line 19, is equivalent to

forlb(j, 0, extra.size(), -1)

Which, from line 17, is equivalent to

for(int63 name = extra.size() - 1; name >= 0; name += -1)

Since extra.size() is of type unsigned int, your code crashes when it is equal to 0.

REAL reason: Your macro sucks massive huge enormous balls. Consider scrapping it for the sake of debuggability :-s

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

    it was not true, as I told, the code passed correctly when I ran the same input on my computer. to be sure, I just put it in an online debugger — https://www.onlinegdb.com/ — and it took 0.25 seconds at the slow environment. definitely not 2 seconds

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

      Well, it might be the case that size_t — the type of vector::size() is defined to be int or long long on your machine. But I'm sure that it is unsigned on Codeforces. Your solution crashes when I run it on Codeforces Custom Invocation. The "TLE" verdict is because extra.size() - 1 is evaluated to be $$$2^{32} - 1$$$, not because of slow performance.

      Anyway, try to keep that in mind and remember to cast the type to int or long long to avoid those situations.