ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1494. Monobilliards

TLE test 28. Why this code is slow ?
Posted by cs_Diablo 22 Dec 2011 16:54
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 ?
Posted by cs_Diablo 22 Dec 2011 16:58
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?