| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Why I Time Limit Exceed???????#include<iostream>
using namespace std;
int main()
{
const long oo=1000000001;
long n,i;
long long ans;
long h[100000],r[100000];
cin >> n;
for (i=1; i<=n; i++) cin >> h[i];
ans=0; r[n]=n; h[n+1]=oo;
for (i=n-1; i>=1; i--)
{
long now;
now=i;
do
{
if (h[now+1]<h[i]) now=r[now+1];
} while (h[now+1]<h[i]);
r[i]=now;
ans+=r[i]-i;
}
cout <<ans <<endl;
return 0;
}
I have tried G++ & C++ complier...
Both are Time Limit Exceed...
Can anyone help me???
Ps:All testdatas I have download from Usaco are passed in 0.43s!!!
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator