結果

問題 No.14 最小公倍数ソート
ユーザー pekempeypekempey
提出日時 2015-08-21 16:57:21
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 923 bytes
コンパイル時間 1,400 ms
コンパイル使用メモリ 146,392 KB
実行使用メモリ 7,916 KB
最終ジャッジ日時 2023-09-25 14:23:55
合計ジャッジ時間 8,560 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
7,564 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 75 ms
4,384 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 <bits/stdc++.h>
#define rep(i, a) rep2 (i, 0, a)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) repr2 (i, 0, a)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define asn(a, b, c) fill_n(&(b), sizeof(a) / sizeof(b), c)
using namespace std;
typedef long long ll;
const ll inf = 1e9;
const ll mod = 1e9 + 7;
const ll infl = 1e18;

ll lcm(ll a, ll b) {
	return a / __gcd(a, b) * b;
}

ostream &operator <<(ostream &os, const vector<ll> &v) {
	rep (i, v.size()) {
		if (i) cout << " ";
		cout << v[i];
	}
	return os;
}

int main() {
	int N;
	cin >> N;
	vector<ll> a(N);
	rep (i, N) cin >> a[i];

	rep (i, N - 1) {
		ll mini = infl;
		ll minv = infl;
		rep2 (j, i + 1, N) {
			ll l = lcm(a[i], a[j]);
			if (l < minv) {
				minv = l;
				mini = j;
			} else if (l == minv && a[mini] > a[j]) {
				mini = j;
			}
		}
		swap(a[i + 1], a[mini]);
	}

	cout << a << endl;

	return 0;
}
0