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

把cin换成scanf试试

Posted by zgw at 2007-11-23 19:01:35 on Problem 3250
In Reply To:Why I Time Limit Exceed??????? Posted by:zhangxiao1124 at 2007-11-23 17:06:36
> #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:
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