結果

問題 No.14 最小公倍数ソート
コンテスト
ユーザー himueu
提出日時 2026-10-16 04:02:14
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 742 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,871 ms
コンパイル使用メモリ 189,232 KB
実行使用メモリ 395,264 KB
最終ジャッジ日時 2026-10-16 04:04:24
合計ジャッジ時間 111,872 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 TLE * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

int main() {
    using namespace std;
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &e : a) { cin >> e; }

    constexpr int m = 10010;
    vector LCM(m, vector<int>(m));
    for (int i = 1; i < m; i++) {
        for (int j = 1; j < m; j++) {
            LCM[i][j] = lcm(i, j);
        }
    }

    for (int i = 0; i < n; i++) {
        sort(a.begin() + i + 1, a.end(), [&](const int x, const int y) {
            if (LCM[x][a[i]] != LCM[y][a[i]]) {
                return LCM[x][a[i]] < LCM[y][a[i]];
            } else {
                return x < y;
            }
        });
    }

    for (auto e : a) { cout << e << " "; }
    cout << endl;
}
0