比赛 |
20161115 |
评测结果 |
WWWWWWWWWW |
题目名称 |
军队 |
最终得分 |
0 |
用户昵称 |
ss |
运行时间 |
0.346 s |
代码语言 |
C++ |
内存使用 |
187.26 MiB |
提交时间 |
2016-11-15 11:20:12 |
显示代码纯文本
- #include<cstdio>
- #include<iostream>
- #include<iomanip>
- using namespace std;
- const int maxn=1000000+10;
- signed int k, total;
- int n, ans;
- int st, en;
- int s[maxn], tt[maxn];
- int check(int ,int );
- int pd(int ,int );
- int main()
- {
- freopen("tarmy.in", "r", stdin);
- freopen("tarmy.out", "w", stdout);
- int i, j;
- scanf("%d%d", &n, &k);
- signed int sp=0;
- for(i=1; i<=n; i++)
- {
- cin>>s[i];
- sp+=s[i];
- if(i>=2)
- {
- if(pd(s[i],s[i-1]))
- tt[i-1]=1;
- else tt[i-1]=0;
- }
- }
- if(sp<=k)
- {
- if(sp<k)
- {
- cout<<"0"<<endl;
- return 0;
- }
- if(sp==k)
- {
- cout<<n<<endl;
- return 0;
- }
- }
- int qq=0, pp=0;
- for(i=1; i<=n-1; i++)
- {
- if(tt[i]==0)
- {
- pp++;
- qq=max(qq,pp);
- }
- if(tt[i]==1)
- {
- pp=0;
- }
- }
- pp=0;
- for(i=1; i<=n-1; i++)
- {
- if(tt[i]==0)
- {
- pp++;
- }
- if(pp==qq)
- {
- en=i+1;
- break;
- }
- if(tt[i]==1) pp=0;
- }
- st=en-qq;
- // cout<<st<<en<<endl;
- for(i=st; i<=en; i++) total+=s[i];
- check(st, en);
- ans=en-st+1;
- // cout<<ans<<endl;
- if(total>=k)
- cout<<ans<<endl;
- else
- cout<<"0"<<endl;
- return 0;
- }
- int check(int x, int y)
- {
- int i, j;
- for(i=x; i<=y; i++)
- {
- if(x!=st||y!=en) break;
- for(j=1; j+i<=y; j++)
- {
- if(!pd(s[i],s[i+j]))
- {
- if(s[i]>s[i+j])
- {
- total-=s[i+j];
- en=i+j;
- }
- else
- {
- total-=s[i];
- st=i+1;
- }
- break;
- }
- }
-
- }
- }
- int pd(int x, int y)
- {
- if(x>y)
- {
- if(x%y==0)
- return 1;
- else return 0;
- }
- if(x<y)
- {
- if(y%x==0)
- return 1;
- else return 0;
- }
- return 1;
- }