結果

問題 No.14 最小公倍数ソート
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-06-11 14:15:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4,551 ms / 5,000 ms
コード長 1,527 bytes
コンパイル時間 1,469 ms
コンパイル使用メモリ 166,944 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 21:02:24
合計ジャッジ時間 51,653 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 48 ms
4,348 KB
testcase_04 AC 4,551 ms
4,348 KB
testcase_05 AC 1,523 ms
4,348 KB
testcase_06 AC 1,785 ms
4,348 KB
testcase_07 AC 2,328 ms
4,348 KB
testcase_08 AC 3,072 ms
4,348 KB
testcase_09 AC 4,190 ms
4,348 KB
testcase_10 AC 4,083 ms
4,348 KB
testcase_11 AC 4,227 ms
4,348 KB
testcase_12 AC 4,356 ms
4,348 KB
testcase_13 AC 4,411 ms
4,348 KB
testcase_14 AC 4,280 ms
4,348 KB
testcase_15 AC 4,435 ms
4,348 KB
testcase_16 AC 1,642 ms
4,348 KB
testcase_17 AC 1,174 ms
4,348 KB
testcase_18 AC 525 ms
4,348 KB
testcase_19 AC 2,779 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std; void _main(); int main(){cin.tie(0);ios::sync_with_stdio(0);_main();}
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/


int gcd(int a, int b) { return a ? gcd(b%a, a) : b; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int N, A[10101];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];
    A[N] = 1;

    rep(i, 0, N) {
        if (0 < i) printf(" ");
        printf("%d", A[i]);

        int mi = i + 1, lc = lcm(A[i], A[i + 1]);
        rep(j, i + 2, N) {
            int x = lcm(A[i], A[j]);
            if (x < lc) {
                mi = j, lc = x;
            } else if (x == lc && A[j] < A[mi]) {
                mi = j, lc = x;
            }
        }
        swap(A[i + 1], A[mi]);
    }
    printf("\n");
}
0