結果
| 問題 |
No.14 最小公倍数ソート
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-10-03 12:51:03 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 51 ms / 5,000 ms |
| コード長 | 1,187 bytes |
| コンパイル時間 | 3,486 ms |
| コンパイル使用メモリ | 281,096 KB |
| 実行使用メモリ | 12,540 KB |
| 最終ジャッジ日時 | 2025-10-03 12:51:09 |
| 合計ジャッジ時間 | 5,907 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
// #pragma GCC optimize ("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target ("avx,avx2,fma")
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i <= (b); i ++)
using std::cin, std::cout, std::cerr;
using ll = long long;
const int N = 1e5 + 1;
std::multiset<int> set[N];
std::vector<int> Divs(int x) {
std::vector<int> r;
for(int i = 1; i * i <= x; i ++) if(x % i == 0) {
r.push_back(i);
if(i != x / i)
r.push_back(x / i);
}
return r;
}
int main() {
std::ios::sync_with_stdio(false);
int n; cin >> n;
int x; cin >> x; cout << x << ' ';
rep(i, 2, n) {
int y; cin >> y;
for(int i : Divs(y))
set[i].insert(y);
}
rep(i, 2, n) {
int y = -1;
ll min = 1e18L;
for(int i : Divs(x)) if(!set[i].empty()) {
int z = *set[i].begin();
ll lcm = ll(x) * z / i;
if(lcm < min || (lcm == min && z < y)) {
min = lcm;
y = z;
}
}
for(int i : Divs(y))
set[i].erase(set[i].find(y));
x = y;
cout << x << ' ';
}
cout << '\n';
}