結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー yasuwoyasuwo
提出日時 2021-11-27 16:48:36
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,506 bytes
コンパイル時間 5,284 ms
コンパイル使用メモリ 312,636 KB
実行使用メモリ 14,184 KB
最終ジャッジ日時 2023-09-12 20:05:18
合計ジャッジ時間 28,049 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 6 ms
10,940 KB
testcase_02 AC 5 ms
10,856 KB
testcase_03 AC 6 ms
10,832 KB
testcase_04 AC 6 ms
10,796 KB
testcase_05 AC 6 ms
10,864 KB
testcase_06 AC 6 ms
10,840 KB
testcase_07 AC 6 ms
10,796 KB
testcase_08 AC 5 ms
10,880 KB
testcase_09 AC 5 ms
10,756 KB
testcase_10 AC 6 ms
10,852 KB
testcase_11 AC 5 ms
10,748 KB
testcase_12 AC 4 ms
10,896 KB
testcase_13 AC 1,451 ms
13,916 KB
testcase_14 AC 1,453 ms
13,972 KB
testcase_15 AC 1,429 ms
13,912 KB
testcase_16 AC 1,446 ms
14,024 KB
testcase_17 AC 1,436 ms
13,964 KB
testcase_18 AC 684 ms
13,928 KB
testcase_19 AC 1,980 ms
14,184 KB
testcase_20 AC 281 ms
13,916 KB
testcase_21 AC 284 ms
13,916 KB
testcase_22 TLE -
testcase_23 AC 35 ms
14,032 KB
testcase_24 AC 36 ms
13,920 KB
testcase_25 AC 1,290 ms
13,916 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<ll> solve(int N, const std::vector<long long> &A)
{
    vector<ll> cnt(1e6 + 1, 0);
    for (ll a : A)
    {
        auto d = divisor(a);
        for (ll x : d)
        {
            cnt[x]++;
        }
    }
    vector<ll> res(N, 0);
    for (ll 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;
    std::vector<long long> A(N);
    for (int i = 0; i < N; ++i)
    {
        std::cin >> A[i];
    }
    auto ans = solve(N, A);
    for (int i = 0; i < N; ++i)
    {
        std::cout << ans[i] << '\n';
    }
    return 0;
}
0