結果

問題 No.14 最小公倍数ソート
ユーザー 古寺いろは古寺いろは
提出日時 2015-04-15 23:52:04
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 780 bytes
コンパイル時間 1,481 ms
コンパイル使用メモリ 157,852 KB
実行使用メモリ 199,744 KB
最終ジャッジ日時 2023-09-17 20:32:17
合計ジャッジ時間 9,745 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 894 ms
46,968 KB
testcase_04 TLE -
testcase_05 AC 1,607 ms
73,416 KB
testcase_06 AC 2,341 ms
98,676 KB
testcase_07 AC 3,040 ms
123,092 KB
testcase_08 AC 4,135 ms
155,404 KB
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 AC 4,169 ms
150,588 KB
testcase_17 AC 3,583 ms
136,680 KB
testcase_18 AC 2,353 ms
97,700 KB
testcase_19 AC 4,868 ms
175,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	map<int, int> m;
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
		m[A[i]]++;
	}
	int next = A[0];
	m[next]--;
	cout << next;
	for (int i = 0; i < N - 1; i++)
	{
		vector<int> divisor;
		for (int j = 1; j <= next; j++)
		{
			if (next % j == 0){
				divisor.push_back(j);
				if(j * j != next) divisor.push_back(next / j);
			}
		}

		sort(divisor.begin(), divisor.end());
		int ans = 0;
		for (int j = 1; j <= 10000; j++)
		{
			for (int k: divisor)
			{
				int target = j * k;
				if (m[target]){
					ans = target;
					break;
				}
				if (target >= 10000) break;
			}
			if (ans) break;
		}

		next = ans;
		m[next]--;
		cout << " " << next;
	}
	cout << endl;
	cin >> N;
}



0