duckduckMoose's blog

By duckduckMoose, history, 4 years ago, In English

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?

  • Vote: I like it
  • +3
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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.