結果
問題 | No.14 最小公倍数ソート |
ユーザー |
![]() |
提出日時 | 2015-04-15 23:52:04 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 780 bytes |
コンパイル時間 | 1,976 ms |
コンパイル使用メモリ | 168,916 KB |
実行使用メモリ | 203,680 KB |
最終ジャッジ日時 | 2025-03-23 05:50:40 |
合計ジャッジ時間 | 10,035 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 TLE * 1 -- * 15 |
ソースコード
#include "bits/stdc++.h" using namespace std; int main() { int N; cin >> N; vector<int> A(N); map<int, int> m; 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 ans = 0; for (int j = 1; j <= 10000; j++) { for (int k: divisor) { int target = j * k; if (m[target]){ ans = target; break; } if (target >= 10000) break; } if (ans) break; } next = ans; m[next]--; cout << " " << next; } cout << endl; cin >> N; }