結果

問題 No.14 最小公倍数ソート
ユーザー chocoruskchocorusk
提出日時 2018-12-11 03:05:36
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 979 bytes
コンパイル時間 1,368 ms
コンパイル使用メモリ 92,700 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 22:23:24
合計ジャッジ時間 8,493 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int gcd(int a, int b){
	if(b==0) return a;
	return gcd(b, a%b);
}
int main()
{
	int n;
	cin>>n;
	int a[10000];
	for(int i=0; i<n; i++) cin>>a[i];
	bool used[10000]={};
	int ans[10000];
	ans[0]=a[0];
	used[0]=1;
	for(int i=1; i<n; i++){
		int mx0=10001, mx1=10001, i0=-1;
		for(int j=0; j<n; j++){
			if(used[j]) continue;
			int l=a[j]/gcd(a[j], ans[i-1])*ans[i-1];
			if(mx0>l){
				mx0=l;
				mx1=a[j];
				i0=j;
			}else if(mx0==l && mx1>a[j]){
				mx1=a[j];
				i0=j;
			}
		}
		used[i0]=1;
		ans[i]=a[i0];
	}
	for(int i=0; i<n; i++){
		cout<<ans[i];
		if(i<n-1) cout<<" ";
	}
	cout<<endl;
	return 0;
}
0