Блог пользователя M.A.H.M.O.O.D

Автор M.A.H.M.O.O.D, история, 8 лет назад, По-английски

Good day everyone,

Today I was solving 731C - Socks and I was getting TLE on test 32.

I really have no idea what is causing the TLE can somebody please help me ?

Note: that in my submission my code gave an answer but still it was counted as TLE.

My submission: 22259984.

Thank you for reading.

:)

Теги dfs, tle
  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

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

Use a map to store count instead of an array . That's what causes tle .

  • »
    »
    8 лет назад, # ^ |
      Проголосовать: нравится -6 Проголосовать: не нравится

    Shouldn't maps have a log(n) complexity to access a value and shouldn't the array's complexity be (1) ?

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

memset(countt, 0, sizeof(countt)); works in O(n). Try to use map for counting and clear it after each dfs.