求大佬hack一下E

#include <bits/stdc++.h>
using namespace std;
void SOLVE()
{
    int n;
    cin >> n;
    vector<int> a(n + 10), v[n + 10];
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (i == j)
                continue;
            if (__gcd(a[i], a[j]) != 1)
            {
                v[i].push_back(j);
            }
        }
    }
    for (int i = 1; i <= n; i++)
    {
        if (v[i].size() == 0)
        {
            cout << -1 << '\n';
            return;
        }
    }
    int l = 1, r = 2;
    int ans = 1;
    while (l < r && r < n - 1)
    {
        bool ok1 = true, ok2 = true;
        for (int i = l; i <= r; i++)
        {
            auto cnt = upper_bound(v[i].begin(), v[i].end(), r) - lower_bound(v[i].begin(), v[i].end(), l);
            if (cnt == 0)
            {
                ok1 = false;
            }
        }
        for (int i = r + 1; i <= n; i++)
        {
            auto cnt = upper_bound(v[i].begin(), v[i].end(), n) - lower_bound(v[i].begin(), v[i].end(), r + 1);
            if (cnt == 0)
            {
                ok2 = false;
            }
        }
        if (ok1 && ok2)
        {
            ans++;
            l = r + 1;
            r = r + 2;
            continue;
        }
        r++;
    }
    cout << ans << '\n';
}
auto main() -> signed
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int __ = 1;
    // for (cin >> __; __--;)
    SOLVE();
    return 0;
}

全部评论

相关推荐

08-28 20:36
门头沟学院 Java
点赞 评论 收藏
分享
沐芷凌曦:这简历数分别指望了,数分最基本的SQL能力你的经历是完全没办法佐证的,而且简历排版极其混乱。你的奖项为什么要写具体的项目内容;教育经历为什么要写你在什么课学到了什么东西,这些都应该是在专业技能里的;专业技能里你又把项目的内容放了进来,而且专业技能你又在强调ETL,如果说你确定要把ETL作为你专业技能的主体那你的经历为什么不能重点佐证呢;反而项目经历你项目等于你调用PyEcharts做了一个看板,就是最基本的课程设计,也是没办法佐证你对PyEcharts的掌握程度,而且没有说具体用什么技术做了什么东西中间做了什么最终得到了什么结果。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务