HDU 4648 Magic Pen 6

题目链接

6Y什么水平。。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <string>
 4 #include <algorithm>
 5 using namespace std;
 6 #define LL __int64
 7 #define INF 10000000
 8 int dp1[10001];
 9 int dp2[10001];
10 LL p[200001];
11 LL sum[200001];
12 int main()
13 {
14     int n,m,i,ans;
15     while(scanf("%d%d",&n,&m)!=EOF)
16     {
17         memset(sum,0,sizeof(sum));
18         for(i = 0;i < m;i ++)
19         {
20             dp1[i] = -INF;
21             dp2[i] = INF;
22         }
23         ans = 0;
24         for(i = 1;i <= n;i ++)
25         {
26             scanf("%I64d",&p[i]);
27             sum[i] = sum[i-1] + p[i];
28             sum[i]%= m;
29             if(sum[i] < 0)
30             sum[i] += m;
31             if(sum[i] == 0) ans = max(ans,i);
32             dp1[sum[i]] = max(dp1[sum[i]],i);
33             dp2[sum[i]] = min(dp2[sum[i]],i);
34         }
35         for(i = 1;i < m;i ++)
36         {
37             if(dp2[i] != INF)
38             ans = max(dp1[i]-dp2[i],ans);
39         }
40         printf("%d\n",ans);
41     }
42     return 0;
43 }

 

posted @ 2013-08-06 19:06  Naix_x  阅读(232)  评论(0编辑  收藏  举报