結果

問題 No.14 最小公倍数ソート
ユーザー koba-e964koba-e964
提出日時 2015-05-03 17:17:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4,998 ms / 5,000 ms
コード長 1,202 bytes
コンパイル時間 893 ms
コンパイル使用メモリ 85,776 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-19 05:19:13
合計ジャッジ時間 56,322 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 52 ms
4,376 KB
testcase_04 AC 4,998 ms
4,380 KB
testcase_05 AC 1,684 ms
4,380 KB
testcase_06 AC 1,961 ms
4,376 KB
testcase_07 AC 2,559 ms
4,376 KB
testcase_08 AC 3,371 ms
4,384 KB
testcase_09 AC 4,555 ms
4,380 KB
testcase_10 AC 4,475 ms
4,376 KB
testcase_11 AC 4,646 ms
4,380 KB
testcase_12 AC 4,779 ms
4,380 KB
testcase_13 AC 4,851 ms
4,376 KB
testcase_14 AC 4,712 ms
4,380 KB
testcase_15 AC 4,855 ms
4,376 KB
testcase_16 AC 1,799 ms
4,380 KB
testcase_17 AC 1,287 ms
4,380 KB
testcase_18 AC 571 ms
4,380 KB
testcase_19 AC 3,041 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef pair<int, int> PI;
const double EPS=1e-9;

int n;
const int N = 10010;

int a[N];

int b[N];
int u[N];

int lcm(int x, int y) {
  return x / __gcd(x, y) * y;
}

int main(void){
  cin >> n;
  REP(i, 0, n) {
    cin >> a[i];
    u[i] = 0;
  }
  int s = 0;
  REP(i, 0, n) {
    b[i] = a[s];
    u[s] = 1;
    int mini = -1;
    int minl = 0;
    REP(k, 0, n) {
      if (u[k]) {
        continue;
      }
      int l = lcm(a[s], a[k]);
      if (mini == -1 || minl > l ||
          (minl == l && a[mini] > a[k])) {
        mini = k;
        minl = l;
      }
    }
    s = mini;
  }
  REP(i, 0, n) {
    cout << b[i] << (i == n - 1 ? "\n" : " ");
  }
}
0