kartik_singh29's blog

By kartik_singh29, history, 6 years ago, In English

Hi , I am unable to understand why my solution gives TLE on test case 4 .

Link to my solution — https://codeforces.me/contest/1529/submission/117265714

It would helpful if someone could point out the flaw in the solution . Thanks in advance !!

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

»
6 years ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

Just add these lines in the main. ~~~~~ ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); ~~~~~

»
6 years ago, hide # |
← Rev. 2  
Vote: I like it 0 Vote: I do not like it

Had the same problem as you, you have to use fast input (i.e. paste this lines at the beggining of main so that the input is readed faster):

ios::sync_with_stdio(false); cin.tie(NULL);

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

Hey you are doing some extra work like initializing whole dp array everytime and using endl, so it's a good practice to use faster input/output i.e, ios_base::sync_with_stdio(0);cin.tie(0);, so that the code doesn't TLE, otherwise the code is fine.