結果
問題 |
No.14 最小公倍数ソート
|
ユーザー |
![]() |
提出日時 | 2015-04-16 00:03:00 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 158 ms / 5,000 ms |
コード長 | 797 bytes |
コンパイル時間 | 1,369 ms |
コンパイル使用メモリ | 164,064 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-04 14:41:02 |
合計ジャッジ時間 | 4,074 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
#include "bits/stdc++.h" using namespace std; int dp[10001]; int m[10001]; int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; m[A[i]]++; } int next = A[0]; m[next]--; cout << next; for (int i = 0; i < N - 1; i++) { vector<int> divisor; for (int j = 1; j <= next; j++) { if (next % j == 0){ divisor.push_back(j); if(j * j != next) divisor.push_back(next / j); } } sort(divisor.begin(), divisor.end()); int check = 99999; int ans = 0; for (auto d: divisor) { while (d * dp[d] <= 10000){ if (m[d * dp[d]]){ if (dp[d] < check){ ans = d * dp[d]; check = dp[d]; } break; } else dp[d]++; } } next = ans; m[next]--; cout << " " << next; } cout << endl; }