結果

問題 No.14 最小公倍数ソート
ユーザー pekempeypekempey
提出日時 2015-10-23 17:54:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4,534 ms / 5,000 ms
コード長 1,069 bytes
コンパイル時間 1,291 ms
コンパイル使用メモリ 145,984 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-29 17:43:00
合計ジャッジ時間 51,938 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 48 ms
4,380 KB
testcase_04 AC 4,534 ms
4,380 KB
testcase_05 AC 1,524 ms
4,380 KB
testcase_06 AC 1,782 ms
4,380 KB
testcase_07 AC 2,326 ms
4,376 KB
testcase_08 AC 3,061 ms
4,376 KB
testcase_09 AC 4,138 ms
4,380 KB
testcase_10 AC 4,047 ms
4,380 KB
testcase_11 AC 4,195 ms
4,376 KB
testcase_12 AC 4,348 ms
4,376 KB
testcase_13 AC 4,390 ms
4,376 KB
testcase_14 AC 4,273 ms
4,376 KB
testcase_15 AC 4,408 ms
4,380 KB
testcase_16 AC 1,631 ms
4,376 KB
testcase_17 AC 1,170 ms
4,376 KB
testcase_18 AC 517 ms
4,376 KB
testcase_19 AC 2,752 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define GET_MACRO(a, b, c, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define rep2(i, a) rep3 (i, 0, a)
#define rep3(i, a, b) for (int i = (a); i < (b); i++)
#define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__)
#define repr2(i, a) repr3 (i, 0, a)
#define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define chmin(a, b) ((b) < a && (a = (b), true))
#define chmax(a, b) (a < (b) && (a = (b), true))
using namespace std;
typedef long long ll;

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

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

int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	rep (i, N) cin >> a[i];
	rep (i, N - 1) {
		int mni = -1, mn = 1e9;
		rep (j, i + 1, N) {
			int l = lcm(a[i], a[j]);
			if (mn > l) {
				mn = l;
				mni = j;
			} else if (mn == l && a[mni] > a[j]) {
				mni = j;
			}
		}
		swap(a[i + 1], a[mni]);
	}	
	cout << a << endl;
	return 0;
}
0