結果

問題 No.14 最小公倍数ソート
ユーザー chocoruskchocorusk
提出日時 2018-12-11 03:07:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4,888 ms / 5,000 ms
コード長 970 bytes
コンパイル時間 1,945 ms
コンパイル使用メモリ 93,532 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 22:25:31
合計ジャッジ時間 55,478 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,356 KB
testcase_03 AC 51 ms
4,352 KB
testcase_04 AC 4,888 ms
4,348 KB
testcase_05 AC 1,641 ms
4,356 KB
testcase_06 AC 1,918 ms
4,348 KB
testcase_07 AC 2,504 ms
4,348 KB
testcase_08 AC 3,299 ms
4,348 KB
testcase_09 AC 4,448 ms
4,352 KB
testcase_10 AC 4,377 ms
4,348 KB
testcase_11 AC 4,535 ms
4,352 KB
testcase_12 AC 4,660 ms
4,352 KB
testcase_13 AC 4,738 ms
4,352 KB
testcase_14 AC 4,594 ms
4,348 KB
testcase_15 AC 4,751 ms
4,352 KB
testcase_16 AC 1,758 ms
4,348 KB
testcase_17 AC 1,257 ms
4,352 KB
testcase_18 AC 559 ms
4,352 KB
testcase_19 AC 2,976 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

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]);
			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