結果

問題 No.14 最小公倍数ソート
ユーザー tottoripapertottoripaper
提出日時 2014-11-16 06:17:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4,543 ms / 5,000 ms
コード長 621 bytes
コンパイル時間 1,192 ms
コンパイル使用メモリ 59,920 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 07:09:44
合計ジャッジ時間 51,134 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 48 ms
4,376 KB
testcase_04 AC 4,543 ms
4,380 KB
testcase_05 AC 1,522 ms
4,376 KB
testcase_06 AC 1,778 ms
4,376 KB
testcase_07 AC 2,319 ms
4,380 KB
testcase_08 AC 3,062 ms
4,380 KB
testcase_09 AC 4,136 ms
4,376 KB
testcase_10 AC 4,077 ms
4,376 KB
testcase_11 AC 4,216 ms
4,376 KB
testcase_12 AC 4,339 ms
4,380 KB
testcase_13 AC 4,392 ms
4,380 KB
testcase_14 AC 4,269 ms
4,376 KB
testcase_15 AC 4,418 ms
4,380 KB
testcase_16 AC 1,635 ms
4,376 KB
testcase_17 AC 1,169 ms
4,380 KB
testcase_18 AC 519 ms
4,376 KB
testcase_19 AC 2,767 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <algorithm>

int N, A[10000];

int main(){
    scanf("%d", &N);
    for(int i=0;i<N;i++){scanf("%d", A+i);}

    for(int i=1;i<N;i++){
        int mn = 1001001001, mn_v = 1001001001;
        for(int j=i;j<N;j++){
            int x = A[j] / std::__gcd(A[j], A[i-1]);
            if(x < mn_v || x == mn_v && A[j] < A[mn]){
                mn_v = x;
                mn = j;
            }
        }
        std::swap(A[i], A[mn]);
    }

    for(int i=0;i<N;i++){
        if(i == N-1){printf("%d\n", A[i]);}
        else{printf("%d ", A[i]);}
    }
}
0