Блог пользователя inbarin

Автор inbarin, история, 5 лет назад, По-английски

as I submitted my code to D (1 or 2, doesn't matter) it had TLE at test 2. https://mirror.codeforces.com/contest/1326/submission/73715713 I reshuffled the code and it passed. https://mirror.codeforces.com/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?

  • Проголосовать: нравится
  • -2
  • Проголосовать: не нравится

»
5 лет назад, # |
  Проголосовать: нравится +35 Проголосовать: не нравится

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 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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 лет назад, # ^ |
        Проголосовать: нравится +15 Проголосовать: не нравится

      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.