|
|
back to boardTLE test 28. Why this code is slow ? I've got TLE on test no. 28; here is the "main" piece of code, im wondering why it is slow. Isn't O(n) complexity? Thanks to everyone who help me in advance. Here is the code void solve() { int p=1; f(i,1,n) { f(j,p,b[i]) { if (!used[j]) { s.push(j); used[j]=1; } } if (s.top()==b[i]) s.pop(); else { cout<<"Cheater\n"; return; }
p=b[i]; }
if (s.empty()) cout<<"Not a proof\n"; else cout<<"Cheater\n"; } Here f(i,beg,end) == for(int i=beg; i<=end; i++), s-STL stack<int>, b[] contains the input and used[] is a control array which shows me if ball with number i was already used. Can someone give me a test on which this code will TL ? Re: TLE test 28. Why this code is slow ? To anyone who has the same problem, let's try this test: 100000 1 100000 2 99999 3 99998 ... 49999 50000 It gives me TL cause of the inside cycle f(i,p,b[i]) Re: TLE test 28. Why this code is slow ? Posted by Hexter 12 May 2018 10:00 I tried this test, but there is TL. In VS this test takes less then 40 ms. What's this test 28? |
|
|