結果

問題 No.14 最小公倍数ソート
ユーザー kimiyukikimiyuki
提出日時 2017-01-04 18:19:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 671 bytes
コンパイル時間 690 ms
コンパイル使用メモリ 73,580 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-22 18:54:03
合計ジャッジ時間 60,907 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 62 ms
4,376 KB
testcase_04 TLE -
testcase_05 AC 1,817 ms
4,376 KB
testcase_06 AC 2,126 ms
4,380 KB
testcase_07 AC 2,768 ms
4,380 KB
testcase_08 AC 3,638 ms
4,376 KB
testcase_09 AC 4,906 ms
4,376 KB
testcase_10 AC 4,830 ms
4,376 KB
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 AC 1,967 ms
4,376 KB
testcase_17 AC 1,415 ms
4,380 KB
testcase_18 AC 639 ms
4,376 KB
testcase_19 AC 3,309 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0