結果

問題 No.14 最小公倍数ソート
ユーザー motxxmotxx
提出日時 2014-11-02 01:49:41
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 710 bytes
コンパイル時間 1,191 ms
コンパイル使用メモリ 145,548 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2023-08-29 00:14:07
合計ジャッジ時間 7,993 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 149 ms
4,380 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:18:9: warning: ‘idx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     int idx, raw = 1<<29;
         ^~~

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
inline ll lcm(ll a, ll b) { return a*b/__gcd(a,b); }

int main() {
  int N; cin >> N;
  int a[N], res[N];
  for(int i=0;i<N;i++) cin >> a[i];
  res[0] = a[0];
  int rcnt = 1;
  for(int i=0;i<N-1;i++) {
    ll mn = 1<<29;
    for(int j=i+1;j<N;j++) {
      mn = min(mn, lcm(res[i], a[j]));
    }
    int idx, raw = 1<<29;
    for(int j=i+1;j<N;j++) {
      if(mn == lcm(res[i], a[j])) {
        if(a[j] < raw) { raw = a[j]; idx = j; }
      }
    }
    swap(a[i+1], a[idx]);
    res[rcnt++] = raw;
  }
  
  for(int i=0;i<N;i++) {
    if(i) cout << " ";
    cout << res[i];
  } cout << endl;
  
  return 0;
}
0