比赛 20161115 评测结果 AAATTTTTTT
题目名称 军队 最终得分 30
用户昵称 sxysxy 运行时间 7.170 s
代码语言 C++ 内存使用 2.20 MiB
提交时间 2016-11-15 11:03:54
显示代码纯文本
#include <cstdio>
#include <cstdlib>
#include <cstdarg>
#include <cstdlib>
#include <cstring>
#include <list>
#include <queue>
#include <vector>
#include <functional>
#include <string>
using namespace std;
int gcd(int a, int b)
{
    return b?gcd(b, a%b):a;
}
int a[100002];

/*
struct node
{
    int l, r;
    int ls, rs;
    int v;
}ns[200005];
int last = 1;
#define ld ns[d.ls]
#define rd ns[d.rs]
void pushup(node &d)
{
    if(d.ls && d.rs)
        d.v = gcd(ld.v, rd.v);
    else if(d.ls)d.v = ld.v;
    else d.v = rd.v;
}
int build(int l, int r)
{
    if(l > r)return 0;
    int c = last++;
    node &d = ns[c];
    d.l = l;
    d.r = r;
    if(l == r)d.v = a[l];
    else
    {
        int m = (l+r)>>1;
        d.ls = build(l, m);
        d.rs = build(m+1, r);
        pushup(d);
    }
    return c;
}
int qans;
void query(int c, int l, int r)
{
    if(!c)return;
    node &d = ns[c];
    if(l == d.l && d.r == r)
        qans = gcd(qans, d.v);
    else
    {
        if(l >= rd.l)query(d.rs, l, r);
        else if(r <= ld.r)query(d.ls, l, r);
        else
        {
            query(d.ls, l, ld.r);
            query(d.rs, rd.l, r);
        }
    }
}
*/

typedef long long LL;
LL s[100002];
LL lens[100002];
int n, k;
int res = 0;
bool check(int len)
{
    bool f1 = false;
    for(int i = 1; i <= n-len+1; i++)
    {
        lens[i] = s[i+len-1]-s[i-1];
        if(lens[i] >= k)f1 = true;
    }
    if(!f1)return false;
    for(int i = 1; i <= n-len+1; i++)
        if(lens[i] >= k)
        {
            bool f2 = true;
            for(int j = i; j <= i+len-1; j++)
                for(int p = j+1; p <= i+len-1; p++)
                    if(gcd(a[p], a[j]) != 1)
                        f2 = false;
            if(f2)
            {
                res = max(res, len);
                break;
            }
        }
    return true;
}
int main()
{
    freopen("tarmy.in", "r", stdin);
    freopen("tarmy.out", "w", stdout);
    scanf("%d %d", &n, &k);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", a+i);
        s[i] = a[i]+s[i-1];
    }
    //build(1, n);
    //int ans = 0;
    /*
    int l = 1, r = n;
    while(l <= r)
    {
        int m = (l+r)>>1;
        if(check(m))
        {
            ans = m;
            l = m+1;
        }else r = m-1;
    }*/
    for(int i = 1; i <= n; i++)
        check(i);
    printf("%d\n", res);
    return 0;
}