結果

問題 No.14 最小公倍数ソート
ユーザー y_mazuny_mazun
提出日時 2015-04-24 00:42:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4,743 ms / 5,000 ms
コード長 625 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 51,208 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 09:09:25
合計ジャッジ時間 52,745 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 50 ms
4,380 KB
testcase_04 AC 4,743 ms
4,380 KB
testcase_05 AC 1,592 ms
4,380 KB
testcase_06 AC 1,861 ms
4,380 KB
testcase_07 AC 2,425 ms
4,376 KB
testcase_08 AC 3,194 ms
4,380 KB
testcase_09 AC 4,327 ms
4,380 KB
testcase_10 AC 4,260 ms
4,380 KB
testcase_11 AC 4,403 ms
4,380 KB
testcase_12 AC 4,531 ms
4,376 KB
testcase_13 AC 4,592 ms
4,376 KB
testcase_14 AC 4,460 ms
4,376 KB
testcase_15 AC 4,604 ms
4,376 KB
testcase_16 AC 1,709 ms
4,380 KB
testcase_17 AC 1,222 ms
4,376 KB
testcase_18 AC 542 ms
4,380 KB
testcase_19 AC 2,884 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int main(){
  const int n = getInt();
  vector<int> a(n);
  REP(i,n) a[i] = getInt();

  REP(i,n-1){
    const int aa = a[i];
    pair<int, pair<int, int> > t = make_pair(1000000000, make_pair(0, 0));
    for(int j = i + 1; j < n; j++){
      t = min(t, make_pair(aa * a[j] / __gcd(aa, a[j]), make_pair(a[j], j)));
    }
    swap(a[i + 1], a[t.second.second]);
  }

  REP(i,n) printf("%d ", a[i]);
  puts("");

  return 0;
}
0