結果

問題 No.14 最小公倍数ソート
ユーザー chocoruskchocorusk
提出日時 2018-12-11 03:58:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 57 ms / 5,000 ms
コード長 1,411 bytes
コンパイル時間 1,311 ms
コンパイル使用メモリ 106,896 KB
実行使用メモリ 9,224 KB
最終ジャッジ日時 2023-10-17 14:11:50
合計ジャッジ時間 2,980 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,448 KB
testcase_01 AC 2 ms
4,448 KB
testcase_02 AC 2 ms
4,448 KB
testcase_03 AC 6 ms
4,940 KB
testcase_04 AC 56 ms
9,224 KB
testcase_05 AC 28 ms
7,152 KB
testcase_06 AC 30 ms
7,416 KB
testcase_07 AC 36 ms
7,868 KB
testcase_08 AC 42 ms
8,400 KB
testcase_09 AC 50 ms
8,948 KB
testcase_10 AC 51 ms
8,908 KB
testcase_11 AC 54 ms
9,088 KB
testcase_12 AC 54 ms
9,072 KB
testcase_13 AC 57 ms
9,120 KB
testcase_14 AC 54 ms
9,040 KB
testcase_15 AC 55 ms
9,176 KB
testcase_16 AC 31 ms
7,388 KB
testcase_17 AC 25 ms
6,892 KB
testcase_18 AC 16 ms
6,088 KB
testcase_19 AC 41 ms
8,228 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:56:32: warning: ‘mna’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   56 |                 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;
	}
	for(int i=1; i<=10000; i++){
	    if(!d[i].empty()) sort(d[i].begin(), d[i].end());
	}
	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