結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー sapphire__15sapphire__15
提出日時 2021-11-06 07:31:42
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,156 ms / 2,000 ms
コード長 2,352 bytes
コンパイル時間 1,336 ms
コンパイル使用メモリ 138,128 KB
実行使用メモリ 8,772 KB
最終ジャッジ日時 2023-08-07 23:28:15
合計ジャッジ時間 13,950 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,156 ms
8,460 KB
testcase_01 AC 4 ms
7,012 KB
testcase_02 AC 4 ms
6,992 KB
testcase_03 AC 5 ms
6,844 KB
testcase_04 AC 4 ms
6,876 KB
testcase_05 AC 4 ms
6,876 KB
testcase_06 AC 4 ms
6,920 KB
testcase_07 AC 4 ms
7,012 KB
testcase_08 AC 4 ms
6,976 KB
testcase_09 AC 4 ms
6,944 KB
testcase_10 AC 4 ms
7,052 KB
testcase_11 AC 4 ms
6,932 KB
testcase_12 AC 5 ms
7,120 KB
testcase_13 AC 805 ms
8,504 KB
testcase_14 AC 814 ms
8,604 KB
testcase_15 AC 807 ms
8,516 KB
testcase_16 AC 813 ms
8,592 KB
testcase_17 AC 808 ms
8,572 KB
testcase_18 AC 541 ms
8,452 KB
testcase_19 AC 989 ms
8,464 KB
testcase_20 AC 399 ms
8,772 KB
testcase_21 AC 399 ms
8,536 KB
testcase_22 AC 1,009 ms
8,456 KB
testcase_23 AC 292 ms
8,596 KB
testcase_24 AC 290 ms
8,460 KB
testcase_25 AC 744 ms
8,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <random>
#include <complex>
#include <bitset>
#include <iomanip>
#include <memory>
#include <chrono>
#include <functional>

#define rep(i, n, s) for(int i = (s); i < int(n); i++)
#define per(i, n, s) for(int i = (n - 1); i >= int(s); i--)
#define MM << " " <<
#define all(x) x.begin(), x.end()
#define rall(x) rbegin(x), rend(x)

template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T>
using MaxHeap = std::priority_queue<T>;

using ll = long long;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;
using Pdd = std::pair<double, double>;

template <class T>
bool chmin(T &a, const T b) {
    if (a > b) {
        a = b;
        return true;
    } else {
        return false;
    }
}

template <class T>
bool chmax(T &a, const T b) {
    if (a < b) {
        a = b;
        return true;
    } else {
        return false;
    }
}

template <class T>
void vdeb(const std::vector<T> &da) {
    auto n = da.size();
    for (size_t i = 0; i < n; i++) {
        if (i == n - 1)
            std::cout << da[i];
        else
            std::cout << da[i] << " ";
    }
    std::cout << std::endl;
}
template<class T>
void vdeb(const std::vector<std::vector<T>> &da) {
    auto n = da.size();
    for (size_t i = 0; i < n; i++) {
        std::cout << i << " : ";
        vdeb(da[i]);
    }
    std::cout << std::endl;
}

template <>
void vdeb(const std::vector<std::string> &da) {
    auto n = da.size();
    for (size_t i = 0; i < n; i++) { std::cout << da[i] << std::endl; }
}

using namespace std;

const int M = 1000001;

int main() {
    int n; cin >> n;
    vector<int> da(n);
    rep(i,n,0) cin >> da[i];
    vector<int> cnt(M);
    rep(i,n,0) {
        for(int j = 1; j*j <= da[i]; j++) {
            if(da[i] % j == 0) {
                cnt[j]++;
                if(j*j != da[i]) cnt[da[i]/j]++;
            }
        }
    }
    vector<int> ans(n);
    rep(i,M,0) {
        if(cnt[i]) chmax(ans[cnt[i]-1], i);
    }
    per(i,n,1) chmax(ans[i-1], ans[i]);
    reverse(all(ans));
    for(auto i : ans) cout << i << endl;
}
0