Codeforces 1154G(枚举)

Posted alphawa

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces 1154G(枚举)相关的知识,希望对你有一定的参考价值。

我预处理(1e7log(1e7))的因数被T掉了,就不敢往这个复杂度想了……无奈去看AC代码
结果怎么暴举gcd剪一剪小枝就接近3s卡过去了!vector有锅(确信

const int maxn = 1e6 + 5, maxa = 1e7 + 5;
int n, a, l, r;
ll lcm = INF;
int f[maxa], s[maxa];

int main() {
    read(n);
    rep(i, 1, n) {
        read(a);
        if (f[a])   s[a] = i;
        else    f[a] = i;
    }
    rep(d, 1, maxa - 5) {
        vector<pii> v;
        for (int j = 1; j * d <= maxa - 5; j++) {
            if (v.size() >= 2)  break;
            if (f[j * d])   v.push_back({j * d, f[j * d]});
            if (s[j * d])   v.push_back({j * d, s[j * d]});
        }
        if (v.size() < 2)   continue;
        ll tmp = (ll)v[0].first / d * v[1].first;
        if (lcm > tmp) {
            lcm = tmp;
            l = v[0].second;
            r = v[1].second;
        }
    }
    if (l > r)  swap(l, r);
    printf("%d %d
", l, r);
    return 0;
}

以上是关于Codeforces 1154G(枚举)的主要内容,如果未能解决你的问题,请参考以下文章

Educational Codeforces Round 76 F 折半枚举

[Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)][C. Playing Piano](代码片段

Codeforces 425A Sereja and Swaps(暴力枚举)

Codeforces Round #647 (Div. 2) B. Johnny and His Hobbies(枚举)

Codeforces Round #647 (Div. 2) B. Johnny and His Hobbies(枚举)

CodeForces 550B Preparing Olympiad(DFS回溯+暴力枚举)