結果

問題 No.14 最小公倍数ソート
ユーザー chocoruskchocorusk
提出日時 2018-12-11 03:55:28
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,323 bytes
コンパイル時間 2,035 ms
コンパイル使用メモリ 104,184 KB
実行使用メモリ 9,220 KB
最終ジャッジ日時 2023-10-17 14:06:35
合計ジャッジ時間 2,875 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,400 KB
testcase_01 AC 2 ms
4,400 KB
testcase_02 AC 2 ms
4,400 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 -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:53:32: warning: ‘mna’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   53 |                 int mnl=10001, mna;
      |                                ^~~

ソースコード

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];
	bool ok[10001]={};
	vector<int> d[10001];
	multiset<int> st[10001];
	for(int i=0; i<n; i++){
		cin>>a[i];
		for(int j=1; j*j<=a[i]; j++){
			if(a[i]%j==0){
				if(!ok[a[i]]) d[a[i]].push_back(j);
				st[j].insert(a[i]);
				if(j*j<a[i]){
					if(!ok[a[i]]) d[a[i]].push_back(a[i]/j);
					st[a[i]/j].insert(a[i]);
				}
			}
		}
		ok[a[i]]=1;
	}
	int ans[10000];
	ans[0]=a[0];
	for(auto x:d[a[0]]){
		auto itr=st[x].lower_bound(a[0]);
		st[x].erase(itr);
	}
	for(int i=1; i<n; i++){
		int mnl=10001, mna;
		for(auto x:d[ans[i-1]]){
		    if(st[x].empty()) continue;
			int a1=*(st[x].begin());
			if(mnl>a1/x){
				mnl=a1/x;
				mna=a1;
			}
		}
		ans[i]=mna;
		for(auto x:d[mna]){
			auto itr=st[x].lower_bound(mna);
			st[x].erase(itr);
		}
	}
	for(int i=0; i<n; i++){
		cout<<ans[i];
		if(i<n-1) cout<<" ";
	}
	cout<<endl;
	return 0;
}
0