結果

問題 No.14 最小公倍数ソート
ユーザー ynq1242ynq1242
提出日時 2014-10-28 16:22:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,614 bytes
コンパイル時間 607 ms
コンパイル使用メモリ 80,068 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-28 23:15:50
合計ジャッジ時間 46,052 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<sstream>
#include<algorithm>
#include<map>
#include<complex>
#include<ctime>
#include<set>
using namespace std;


#define li			long long int
#define rep(i,to)	for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)	for(li i=(li)(start);i<((li)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define F first
#define S second
#define endl "\n"
#define p2(a,b)		cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		cout<<a<<"\t"<<b<<"\t"<<c<<endl

inline li gcd(li a, li b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	return gcd(b, a%b);
}

inline li lcm(li a, li b){
	li g=gcd(a,b);
	return a*b/g;
}

li a[10010];

int main(){
	ios::sync_with_stdio(false);
	li n;
	cin>>n;
	rin{cin>>a[i];}
	sort(a+1, a+n);
	rep(i,n-1){
		li tmin=bit(55), tmini=bit(55), midx=-1;
		repp(j,i+1, n){
			if(tmin<a[j])break;
			li now=lcm(a[i], a[j]);
			if(now<tmin || (now==tmin && a[j]<a[midx])){
				tmin=now;
				midx=j;
			}
		}
		//cout<<midx<<endl;
		if(midx!=i+1){
			swap(a[midx], a[i+1]);
		}
	}
	rin{cout<<a[i]<<" ";}
	puts("");


	return 0;
}
0