This is in regard with Codeforces Round #660-Div 2 Problem B. I submitted a solution to this problem in O(n) time complexity. It passed all the pretests but gave TLE in system testing but later during practice the same code was accepted.
Solution submitted during contest: https://codeforces.net/contest/1388/submission/88486803 gave TLE.
Solution submitted for practice: https://codeforces.net/contest/1388/submission/88530257 passed all the test cases.
Can anyone explain me why it happened? Thanks in advance!
Auto comment: topic has been updated by Mastermind222 (previous revision, new revision, compare).
Change the line where you wrote
to
writing s = s + '9' makes your algorithm 0(n^2) because you duplicate the variable s every time
Hope this helps :p
Oohkay thanks Gotit!!
O(2*n) ?
It's O(n^2)
thanks for a new information...i used to think those two operations are same
This code is $$$O(n^2)$$$:
But can easily be fixed to be $$$O(n)$$$.
Also personally I think the indentation is a bit confusing, at least indent the inside of the loop and/or add braces:
My guess is maybe the compiler was able to catch this and optimize it the second time? P.S. you never used cin fastio.
Oohkay will take care of that next time..