結果

問題 No.14 最小公倍数ソート
ユーザー pluto77pluto77
提出日時 2018-07-28 11:14:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4,652 ms / 5,000 ms
コード長 482 bytes
コンパイル時間 1,190 ms
コンパイル使用メモリ 145,060 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-19 06:03:21
合計ジャッジ時間 53,151 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 50 ms
4,380 KB
testcase_04 AC 4,652 ms
4,380 KB
testcase_05 AC 1,563 ms
4,380 KB
testcase_06 AC 1,823 ms
4,380 KB
testcase_07 AC 2,383 ms
4,380 KB
testcase_08 AC 3,164 ms
4,380 KB
testcase_09 AC 4,248 ms
4,384 KB
testcase_10 AC 4,168 ms
4,376 KB
testcase_11 AC 4,324 ms
4,380 KB
testcase_12 AC 4,451 ms
4,380 KB
testcase_13 AC 4,504 ms
4,380 KB
testcase_14 AC 4,383 ms
4,376 KB
testcase_15 AC 4,522 ms
4,376 KB
testcase_16 AC 1,678 ms
4,380 KB
testcase_17 AC 1,203 ms
4,380 KB
testcase_18 AC 534 ms
4,380 KB
testcase_19 AC 2,838 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//yuki14
#include <bits/stdc++.h>

using namespace std;

int main(){
 int n;
 cin>>n;
 vector<int> a(n);
 for(int i=0;i<n;i++){
  cin>>a[i];
 }
 for(int i=0;i<n-1;i++){
  int pos=i+1;
  int res=INT_MAX;
  for(int j=pos;j<n;j++){
   int temp=a[i]/__gcd(a[i],a[j])*a[j];
   if(temp<res || (temp==res && a[j]<a[pos])){
    res=temp;
    pos=j;
   }
  }
  swap(a[i+1],a[pos]);
 }
 for(int i=0;i<n;i++){
  if(i==n-1)
   printf("%d\n",a[i]);
  else
   printf("%d ",a[i]);
 }
 return 0;
}
0