結果
問題 | No.1730 GCD on Blackboard in yukicoder |
ユーザー |
|
提出日時 | 2021-11-05 22:29:05 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,606 ms / 2,000 ms |
コード長 | 946 bytes |
コンパイル時間 | 7,391 ms |
コンパイル使用メモリ | 266,396 KB |
最終ジャッジ日時 | 2025-01-25 12:30:45 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 24 |
ソースコード
#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';}