N^2都能过!!!!!!!
/* Easy */ #include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> #include<iostream> #include<queue> #include<map> #include<stack> #include<set> #include<math.h> using namespace std; typedef long long int64; //typedef __int64 int64; typedef pair<int64,int64> PII; #define MP(a,b) make_pair((a),(b)) const int maxn = 100005; const int inf = 0x7fffffff; const double pi=acos(-1.0); const double eps = 1e-8; int a[ maxn ]; int sum[ maxn ]; int main(){ int n,mod; while( scanf("%d%d",&n,&mod)==2 ){ sum[ 0 ] = 0; for( int i=1;i<=n;i++ ){ scanf("%d",&a[i]); sum[ i ] = sum[ i-1 ]+a[ i ]; } int M = 0; for( int i=1;i<=n;i++ ){ for( int j=1;j<=i&&(i-j+1>M);j++ ){ if( (sum[i]-sum[j-1])%mod==0 ){ M = i-j+1; } } } printf("%d ",M); } return 0; }