結果

問題 No.14 最小公倍数ソート
ユーザー Mcpu3Mcpu3
提出日時 2018-12-11 17:32:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 779 bytes
コンパイル時間 2,376 ms
コンパイル使用メモリ 78,412 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 02:49:15
合計ジャッジ時間 58,043 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

struct sequence {
	int a, lcm;
};

bool comp(const sequence &a, const sequence &b) {
	return a.lcm <= b.lcm;
}

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

int LCM(int a, int b) {
	return a * b / gcd(a, b);
}

int main() {
	size_t N;
	sequence tmp1, tmp2;
	vector<sequence> array;
	cin >> N;
	for (size_t i = 0; i < N; ++i) {
		cin >> tmp1.a;
		array.push_back(tmp1);
	}
	for (size_t i = 0; i < N; ++i) {
		tmp1 = array[i];
		for (size_t j = i + 1; j < N; ++j) {
			tmp2 = array[j];
			tmp2.lcm = LCM(tmp1.a, tmp2.a);
			array[j] = tmp2;
		}
		stable_sort(array.begin() + i + 1, array.end(), comp);
	}
	for (size_t i = 0; i < N; ++i) {
		tmp1 = array[i];
		cout << tmp1.a << ' ';
	}
}
0