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

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

Hi,

so far I have known that the time complexity for concatenating two strings is O(n). So

while (a.length() < b.length()) a = "0" + a;

is O(n^2). But it still passed the TL: http://codeforces.com/contest/1066/submission/44198754

I am wondering why it passed. Could anyone help me?

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

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

It could be because of optimization. But I am not sure. See here

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

Because it's stored in cache, the compiler sees that its doing same operation every time, it just predicts it will do it again in the next iteration so it adds it to cache.