結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー yasuwoyasuwo
提出日時 2021-11-27 16:51:45
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,536 bytes
コンパイル時間 7,122 ms
コンパイル使用メモリ 315,256 KB
実行使用メモリ 16,908 KB
最終ジャッジ日時 2023-09-12 20:08:54
合計ジャッジ時間 20,955 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
7,716 KB
testcase_01 AC 4 ms
6,944 KB
testcase_02 AC 4 ms
6,952 KB
testcase_03 AC 5 ms
6,984 KB
testcase_04 AC 5 ms
7,192 KB
testcase_05 AC 6 ms
7,016 KB
testcase_06 AC 5 ms
7,020 KB
testcase_07 AC 5 ms
6,952 KB
testcase_08 AC 4 ms
6,948 KB
testcase_09 AC 4 ms
6,964 KB
testcase_10 AC 5 ms
6,984 KB
testcase_11 AC 5 ms
6,988 KB
testcase_12 AC 4 ms
6,928 KB
testcase_13 AC 1,431 ms
16,280 KB
testcase_14 AC 1,426 ms
16,308 KB
testcase_15 AC 1,424 ms
16,388 KB
testcase_16 AC 1,426 ms
16,152 KB
testcase_17 AC 1,421 ms
16,184 KB
testcase_18 AC 738 ms
16,796 KB
testcase_19 TLE -
testcase_20 AC 35 ms
7,812 KB
testcase_21 AC 35 ms
7,768 KB
testcase_22 AC 36 ms
7,984 KB
testcase_23 AC 27 ms
7,708 KB
testcase_24 AC 27 ms
7,816 KB
testcase_25 AC 1,358 ms
16,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "main.cpp"
#include <bits/stdc++.h>
#include <atcoder/all>
// #include "library/templates/template.cpp"
using namespace atcoder;
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

vector<int64_t> divisor(int64_t n)
{
    vector<int64_t> ret;
    for (int64_t 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 (ll 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