結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー yasuwoyasuwo
提出日時 2021-11-27 16:48:36
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,506 bytes
コンパイル時間 5,802 ms
コンパイル使用メモリ 314,748 KB
実行使用メモリ 14,260 KB
最終ジャッジ日時 2024-06-30 07:45:11
合計ジャッジ時間 27,393 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 21 TLE * 3
権限があれば一括ダウンロードができます

ソースコード

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