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

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

I solved Mister B and PR Shifts using trie ... Time complexity of my code is O(n * log(n)) where maximum n = 1000000, but it takes about 1543 ms at least to get the answer, so can anyone please tell me why? Update.. some users advised me to use array instead of pointers with dynamic memory allocation and thats what I did this is the best code I came up with so far .. no dynamic memory allocating . no pointers but my code still too slow and I don't know why http://mirror.codeforces.com/contest/819/submission/28646689

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

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

root = new trie_nod(21);

Memory allocation is costly in terms of runtime. You can avoid it by keeping a static pool of nodes and assigning from there.

Did you implement an array based link list ever? Try to do the same for trie.

»
9 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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