education420's blog

By education420, history, 5 years ago, In English

I have a query related to the time complexity of the code.

Question: https://codeforces.net/problemset/problem/1265/B

My First Solution which was giving me timeout at 6th testcase: https://codeforces.net/contest/1265/submission/67753420

My Second Solution which got accepted: https://codeforces.net/contest/1265/submission/67753486

(Actually this is editorial code, I have copy pasted it).

Can please some one let me know why my first solution is giving me TLE and the second solution is getting accepted.

Merry Christmas.

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
5 years ago, # |
Rev. 5   Vote: I like it +11 Vote: I do not like it

Hello,

if(r-l==i){
    printIt=printIt+'1';
  }else{
    printIt=printIt+'0';
  }

is copying the whole string every time. If you write

if(r-l==i){
    printIt +='1';
  }else{
    printIt +='0';
  }

it will be ACC :)

Hope that helps,

jlohse