結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー bayashi-clbayashi-cl
提出日時 2021-11-05 22:17:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 943 bytes
コンパイル時間 2,348 ms
コンパイル使用メモリ 204,528 KB
実行使用メモリ 33,664 KB
最終ジャッジ日時 2024-04-24 06:06:03
合計ジャッジ時間 24,353 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,792 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 WA -
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 893 ms
14,208 KB
testcase_19 AC 1,779 ms
33,664 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 1,686 ms
5,376 KB
testcase_23 AC 302 ms
5,376 KB
testcase_24 AC 299 ms
5,376 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

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] == -1) ans[i + 1] = ans[i];
    }

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