結果

問題 No.14 最小公倍数ソート
ユーザー y_mazun
提出日時 2015-04-24 00:42:41
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 4,715 ms / 5,000 ms
コード長 625 bytes
コンパイル時間 387 ms
コンパイル使用メモリ 47,940 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-05 00:58:44
合計ジャッジ時間 52,690 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int getInt()’:
main.cpp:6:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 | inline int getInt(){ int s; scanf("%d", &s); return s; }
      |                             ~~~~~^~~~~~~~~~

ソースコード

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