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

Автор aranjuda, 11 лет назад, По-английски

After going through the tutorial and seeing that an O(m*n) algorithm would pass and there was something to do with a "right" array, I coded up a solution that TLEd and then optimized it over XYZ attempts to this:

http://codeforces.net/contest/376/submission/5630035

which still TLEs. A friend optimized it to traverse in column major: http://codeforces.net/contest/376/submission/5631054

which passes. But, when I do the same:

http://codeforces.net/contest/376/submission/5631820

TLE! Any explanations?

Edit: Solved... (change char[] to string)

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

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

When you have two similar solutions, one of which passes and one doesn't, try to find differences.
In this case, try to replace "string" with "char[]" and get AC

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

    Yup, just changed it, thanks :) [Edit: I had somehow not seen the string/char[] difference :| ]

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

You are reading 25 megabytes of data with cin. Try using scanf or gets to read the data.

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

    I used sync_with_stdio(0); though.

    It passed once I changed it to a char array. I guess the overhead with string arrays is too high.