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

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

Hello,

I'm getting time limit exceeded on this problem; 710F - Операции над множеством строк

Any idea how to tweak my solution to avoid this quadratic runtime in method "count". I reviwed others solutions, and they are all quadratic, but why my implementation is just slower?

The nested for loop gives an asymptotic runtime of O(L^2) where L is input string length.

My solution; 20459110

Any hints would be truly appreciated!

Thanks in advance!

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

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

Your implementation of trie for counting procedure will take too much time. So, algorithm runs int O(L^2) , you also notice it. So, as the length could be of L=300000 ,So, Codeforces server could not run 90000000000 operations in 3 seconds. You may generally assume that codeforces server can run 10^8 operation in 1 second. You may solve above problem in O(N*sqrt(N)) by handling small and large queries separately. You may refer to my code for further details. 20158098