sandeep_iitpkd's blog

By sandeep_iitpkd, history, 10 months ago, In English

Hi, there. I have made this submission while I was practicing: Submission link. The time complexity of this code is O(n). But I run the code I am TLE. I have also checked the editorial but I found no use. Beside the question there was an attention that time will be doubled. As I see in the test results the time consumed is 500ms, after getting doubled it becomes 1000ms which is TLE. Can someone help me to figure this out!!

Thank you in advance.

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

»
10 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

I've modified your code a little bit and it is accepted. submission

The main problem is that cin,cout,and endl are slow,so you need to use '\n' instead of endl, and add ios::sync_with_stdio(0);cin.tie(0); to the first line of main function to speed up cin and cout.