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

Re:为什么还是TLE?

Posted by xnslong at 2014-10-23 21:48:54 on Problem 3844
In Reply To:为什么还是TLE? Posted by:sunqian1998 at 2012-05-14 20:46:24
The core part of the program is the same with yours, and I also encountered the same problem. The complexity is O(n) for each case. Why still TLE? Have you got any answer?

> 代码:
> #include<iostream>
> using namespace std;
> int b[1000001]={0};
> int main()
> {
>     int n;
>     cin>>n;
>     for(int i=1;i<=n;i++)
>     {
>       int k,d,a[50000]={0},x;
>       long long ans=0;
>       cin>>k>>d;
>       for(int j=0;j<k;j++) b[j]=0;
>       b[0]=1;
>       for(int j=1;j<=d;j++)
>       {
>          cin>>x;
>          a[j]=a[j-1]+x;
>          a[j]=a[j]%k;
>          b[a[j]]++;
>       }
>       for(int j=0;j<k;j++) ans+=b[j]*(b[j]-1)/2;
>       cout<<ans<<endl;
>     }
>     return 0;
> }
> 还有更简的么?

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