結果

問題 No.14 最小公倍数ソート
ユーザー koba-e964koba-e964
提出日時 2015-05-03 17:13:58
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,184 bytes
コンパイル時間 1,528 ms
コンパイル使用メモリ 87,648 KB
実行使用メモリ 7,612 KB
最終ジャッジ日時 2023-09-19 05:15:27
合計ジャッジ時間 7,989 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 107 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 -- -
権限があれば一括ダウンロードができます

ソースコード

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;
    REP(k, 0, n) {
      if (u[k]) {
	continue;
      }
      if (mini == -1 || lcm(a[s], a[mini]) > lcm(a[s], a[k]) ||
          (lcm(a[s], a[mini]) == lcm(a[s], a[k]) && a[mini] > a[k])) {
        mini = k;
      }
    }
    s = mini;
  }
  REP(i, 0, n) {
    cout << b[i] << (i == n - 1 ? "\n" : " ");
  }
}
0