hdu 4648 Magic Pen 6
水题一枚……
代码如下:
1 #include<iostream> 2 #include<stdio.h> 3 using namespace std; 4 int s[100001],t; 5 int main(){ 6 int n,m,i,j,ans; 7 while(scanf("%d%d",&n,&m)!=EOF){ 8 ans=0; 9 for(i=1;i<=n;i++){ 10 scanf("%d",&t); 11 s[i]=(s[i-1]+t)%m; 12 } 13 for(i=n;i>=1&&i>ans;i--) 14 for(j=1;j+i-1<=n;j++) 15 if((s[i+j-1]-s[j-1])%m==0){ 16 ans=max(i,ans); 17 break; 18 } 19 printf("%d\n",ans); 20 } 21 return 0; 22 }