結果

問題 No.14 最小公倍数ソート
ユーザー tottoripaper
提出日時 2014-11-16 06:17:07
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 4,577 ms / 5,000 ms
コード長 621 bytes
コンパイル時間 537 ms
コンパイル使用メモリ 56,172 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-31 20:41:06
合計ジャッジ時間 51,031 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:8:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
main.cpp:9:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |     for(int i=0;i<N;i++){scanf("%d", A+i);}
      |                          ~~~~~^~~~~~~~~~~

ソースコード

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