結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー bayashi-clbayashi-cl
提出日時 2021-11-05 22:29:05
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,902 ms / 2,000 ms
コード長 946 bytes
コンパイル時間 2,142 ms
コンパイル使用メモリ 209,164 KB
実行使用メモリ 33,352 KB
最終ジャッジ日時 2023-08-07 23:16:13
合計ジャッジ時間 21,173 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,902 ms
4,668 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1,329 ms
22,228 KB
testcase_14 AC 1,312 ms
22,320 KB
testcase_15 AC 1,318 ms
22,268 KB
testcase_16 AC 1,318 ms
22,528 KB
testcase_17 AC 1,328 ms
22,392 KB
testcase_18 AC 655 ms
13,872 KB
testcase_19 AC 1,432 ms
33,352 KB
testcase_20 AC 463 ms
4,700 KB
testcase_21 AC 457 ms
4,632 KB
testcase_22 AC 1,793 ms
4,600 KB
testcase_23 AC 49 ms
4,580 KB
testcase_24 AC 50 ms
4,712 KB
testcase_25 AC 1,027 ms
22,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template <typename T>
vector<T> make_divisor(T n) {
    vector<T> lower, upper;
    T i = 1;

    while (i * i <= n) {
        if (n % i == 0) {
            lower.push_back(i);
            if (T j = n / i; i != j) upper.push_back(j);
        }
        ++i;
    }
    std::reverse(std::begin(upper), std::end(upper));
    std::copy(std::begin(upper), std::end(upper), std::back_inserter(lower));

    return lower;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto&& ai : a) cin >> ai;
    map<int, int> cnt;
    for (auto&& ai : a) {
        for (auto&& div : make_divisor(ai)) {
            cnt[div]++;
        }
    }

    vector<int> ans(n + 1, -1);
    for (auto& [k, v] : cnt) {
        ans[n - v] = k;
    }

    for (int i = 0; i < n - 1; ++i) {
        if (ans[i + 1] < ans[i]) ans[i + 1] = ans[i];
    }

    for (int i = 0; i < n; ++i) cout << ans[i] << '\n';
}
0