M.A.H.M.O.O.D's blog

By M.A.H.M.O.O.D, history, 7 years ago, In English

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.

:)

Tags dfs, tle
  • Vote: I like it
  • +3
  • Vote: I do not like it

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    7 years ago, # ^ |
      Vote: I like it -6 Vote: I do not like it

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

»
7 years ago, # |
  Vote: I like it +8 Vote: I do not like it

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