結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー yasuwoyasuwo
提出日時 2021-11-27 16:56:45
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 688 ms / 2,000 ms
コード長 1,317 bytes
コンパイル時間 3,622 ms
コンパイル使用メモリ 251,132 KB
実行使用メモリ 16,888 KB
最終ジャッジ日時 2023-08-07 23:42:03
合計ジャッジ時間 9,242 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
7,896 KB
testcase_01 AC 4 ms
6,984 KB
testcase_02 AC 4 ms
7,032 KB
testcase_03 AC 4 ms
6,896 KB
testcase_04 AC 5 ms
6,908 KB
testcase_05 AC 5 ms
6,964 KB
testcase_06 AC 4 ms
6,964 KB
testcase_07 AC 4 ms
6,984 KB
testcase_08 AC 4 ms
6,888 KB
testcase_09 AC 4 ms
6,832 KB
testcase_10 AC 5 ms
6,844 KB
testcase_11 AC 4 ms
6,896 KB
testcase_12 AC 4 ms
7,008 KB
testcase_13 AC 518 ms
16,232 KB
testcase_14 AC 517 ms
16,364 KB
testcase_15 AC 519 ms
16,168 KB
testcase_16 AC 519 ms
16,320 KB
testcase_17 AC 515 ms
16,300 KB
testcase_18 AC 287 ms
16,696 KB
testcase_19 AC 688 ms
16,888 KB
testcase_20 AC 35 ms
7,632 KB
testcase_21 AC 35 ms
7,700 KB
testcase_22 AC 35 ms
7,640 KB
testcase_23 AC 27 ms
7,700 KB
testcase_24 AC 27 ms
7,684 KB
testcase_25 AC 474 ms
16,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "main.cpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;

vector<int> divisor(int n)
{
    vector<int> ret;
    for (int i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i * i != n)
                ret.push_back(n / i);
        }
    }
    // sort(begin(ret), end(ret));
    return (ret);
}

template <typename T>
void chmax(T &a, T b) { a = max(a, b); }

vector<int> solve(int N, unordered_map<int, int> &A)
{
    vector<int> cnt(1e6 + 1, 0);
    for (auto [a, c] : A)
    {
        auto d = divisor(a);
        for (int x : d)
        {
            cnt[x] += c;
        }
    }
    vector<int> res(N, 0);
    for (int i = 1; i <= 1e6; i++)
    {
        if (cnt[i])
        {
            chmax(res[N - cnt[i]], i);
        }
    }
    for (int i = 1; i < N; i++)
    {
        chmax(res[i], res[i - 1]);
    }

    return res;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    int N;
    std::cin >> N;
    unordered_map<int, int> A;
    for (int i = 0; i < N; ++i)
    {
        int a;
        cin >> a;
        A[a]++;
    }
    auto ans = solve(N, A);
    for (int i = 0; i < N; ++i)
    {
        std::cout << ans[i] << '\n';
    }
    return 0;
}
0