Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Why I Time Limit Exceed???????

Posted by zhangxiao1124 at 2007-11-23 17:05:08 on Problem 3250
#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???

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator