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 |
Re:为什么还是TLE?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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator