Dealing with '+' and append in C++

Revision en1, by weakestOsuPlayer_244, 2020-06-06 09:48:46

Hello guys.

I was trying the problem https://codeforces.com/contest/182/problem/D

The intended complexity of my solution is supposed to be $$$O(n\sqrt{n})$$$ but somehow I was repeatedly getting TLE. When I switched the concerned part where I was using + for concatenation of two strings with append it got accepted.

I went over to stackoverflow for figuring out the cause but I couldn't understand much of it besides trying the reserve keyword. I also tried using the reserve keyword for reserving space for the string but it resulted in TLE as well.

Here are my submissions:-

https://codeforces.com/contest/182/submission/82678284 -Using append.

https://codeforces.com/contest/182/submission/82677975 -Using + for concatenation.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English weakestOsuPlayer_244 2020-06-06 09:48:46 790 Initial revision (published)