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

Автор duckduckMoose, история, 4 года назад, По-английски

Hi everyone. I was doing 203C. I managed to solve (link) the problem in O(n*log n) time (constraints: n<10^6). But I got TLE. I checked from the editorial and my approach was correct. I read some comments in the editorial suggesting not to use print function and use other methods to print, so I used 'sys.stdout.write'. But then also the problem isn't resolved. How can I print faster than sys.stdout.write?

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

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

I made some changes to the code. Used sys.stdin.readline as input, sorting in place and I used more methods for lists as I thought they would run faster. I got accepted but extremely close to 2 seconds. Here's my code. I think the input made the most difference.