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

Автор kartik_singh29, история, 6 лет назад, По-английски

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 !!

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

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

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

»
6 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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.