結果

問題 No.14 最小公倍数ソート
ユーザー 古寺いろは古寺いろは
提出日時 2015-04-16 00:03:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 180 ms / 5,000 ms
コード長 797 bytes
コンパイル時間 1,405 ms
コンパイル使用メモリ 150,972 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 20:32:23
合計ジャッジ時間 4,621 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 20 ms
4,376 KB
testcase_04 AC 180 ms
4,380 KB
testcase_05 AC 67 ms
4,380 KB
testcase_06 AC 83 ms
4,376 KB
testcase_07 AC 106 ms
4,380 KB
testcase_08 AC 134 ms
4,380 KB
testcase_09 AC 172 ms
4,376 KB
testcase_10 AC 172 ms
4,376 KB
testcase_11 AC 172 ms
4,380 KB
testcase_12 AC 176 ms
4,376 KB
testcase_13 AC 178 ms
4,380 KB
testcase_14 AC 174 ms
4,380 KB
testcase_15 AC 179 ms
4,376 KB
testcase_16 AC 109 ms
4,376 KB
testcase_17 AC 91 ms
4,376 KB
testcase_18 AC 62 ms
4,380 KB
testcase_19 AC 140 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int dp[10001];
int m[10001];

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	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 check = 99999;
		int ans = 0;
		for (auto d: divisor)
		{
			while (d * dp[d] <= 10000){
				if (m[d * dp[d]]){
					if (dp[d] < check){
						ans = d * dp[d];
						check = dp[d];
					}
					break;
				}
				else dp[d]++;
			}
		}
		
		next = ans;
		m[next]--;
		cout << " " << next;
	}
	cout << endl;
}



0