比赛 |
20161115 |
评测结果 |
AAAAAAAAAA |
题目名称 |
军队 |
最终得分 |
100 |
用户昵称 |
Bravo ChaoS |
运行时间 |
0.435 s |
代码语言 |
C++ |
内存使用 |
1.40 MiB |
提交时间 |
2016-11-15 11:54:02 |
显示代码纯文本
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- #include<iostream>
- using namespace std;
-
- class input
- {
- public:
- input& operator >> (int& x)
- {
- char c=' ';x=0;bool flag=0;
- for(;c<'0' || c>'9';c=getchar()) if(c=='-') flag=1;
- for(;c>='0' && c<='9';c=getchar()) x=x*10+c-'0';
- if(flag) x=-x;
- return *this;
- }
- }in;
-
- typedef long long ll;
- const int maxn=100010;
-
- int n,k,a[maxn],cnt(0),len(0);
- bool vis[maxn];
- ll sum[maxn],temp(1);
-
- ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
-
- void Pre()
- {
- for(int i=1,l(1);i<=n;++i)
- {
- if(!len && a[i]>=k) len=1;
- for(int j=l;j<i;++j) if(!vis[i])
- {
- // cout<<i-1<<' '<<l<<endl;
- if(gcd(a[i],a[j])!=1)
- {
- vis[j]=1;
- if(sum[i-1]-sum[l-1]>=k && len<i-l) len=i-l;
- l=j+1;
- }
- }
- }
- }
-
- int main()
- {
- freopen("tarmy.in","r",stdin);
- freopen("tarmy.out","w",stdout);
-
- in>>n>>k;
- for(int i=1;i<=n;++i) in>>a[i],sum[i]=sum[i-1]+a[i];
- Pre();
- printf("%d\n",len);
- fclose(stdin); fclose(stdout);
- return 0;
- }
-
-
-