• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

cynchanpin

  • 博客园
  • 联系
  • 订阅
  • 管理

View Post

HDU 4648 Magic Pen 6

Magic Pen 6

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 2057    Accepted Submission(s): 706


Problem Description
In HIT, many people have a magic pen. Lilu0355 has a magic pen, darkgt has a magic pen, discover has a magic pen. Recently, Timer also got a magic pen from seniors.

At the end of this term, teacher gives Timer a job to deliver the list of N students who fail the course to dean's office. Most of these students are Timer's friends, and Timer doesn't want to see them fail the course. So, Timer decides to use his magic pen to scratch out consecutive names as much as possible. However, teacher has already calculated the sum of all students' scores module M. Then in order not to let the teacher find anything strange, Timer should keep the sum of the rest of students' scores module M the same.

Plans can never keep pace with changes, Timer is too busy to do this job. Therefore, he turns to you. He needs you to program to "save" these students as much as possible.
 

Input
There are multiple test cases.
The first line of each case contains two integer N and M, (0< N <= 100000, 0 < M < 10000),then followed by a line consists of N integers a1,a2,...an (-100000000 <= a1,a2,...an <= 100000000) denoting the score of each student.(Strange score? Yes, in great HIT, everything is possible)
 

Output
For each test case, output the largest number of students you can scratch out.
 

Sample Input
2 3 1 6 3 3 2 3 6 2 5 1 3
 

Sample Output
1 2 0
Hint
The magic pen can be used only once to scratch out consecutive students.
 

Source
2013 Multi-University Training Contest 5 
#include<stdio.h>
const int N = 100005;
#define ll __int64
ll sum[N];
int main(){
    int n,m,ans;
    ll a;
    while(scanf("%d%d",&n,&m)>0){
        sum[0]=0;
        for(int i=1; i<=n; i++){
            scanf("%I64d",&a);
            sum[i]=sum[i-1]+a;
        }
        ans=0;
        for(int i=n; i>=0; i--)
        {
            if(sum[i]%m==0&&ans<i)ans=i;
            for(int j=n; j-i>ans; j--)
            if((sum[j]-sum[i])%m==0){
                ans=j-i; break;
            }
        }
        printf("%d\n",ans);
    }
}


posted on 2017-05-28 21:08  cynchanpin  阅读(145)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3