結果
問題 |
No.14 最小公倍数ソート
|
ユーザー |
|
提出日時 | 2017-01-04 18:19:36 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 671 bytes |
コンパイル時間 | 764 ms |
コンパイル使用メモリ | 73,760 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-17 19:38:03 |
合計ジャッジ時間 | 59,839 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 TLE * 4 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #define repeat(i,n) for (int i = 0; (i) < int(n); ++(i)) using namespace std; template <typename T> T gcd(T a, T b) { while (a) { b %= a; swap(a, b); } return b; } template <typename T> T lcm(T a, T b) { return (a * b) / gcd(a,b); } int main() { int n; cin >> n; vector<int> a(n); repeat (i,n) cin >> a[i]; repeat (i,n-1) { auto it = min_element(a.begin() + i+1, a.end(), [&](int b, int c) { return make_pair(lcm(a[i], b), b) < make_pair(lcm(a[i], c), c); }); swap(a[i+1], *it); } repeat (i,n) cout << (i ? " " : "") << a[i]; cout << endl; return 0; }