結果

問題 No.14 最小公倍数ソート
ユーザー cielciel
提出日時 2014-11-16 17:34:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3,702 ms / 5,000 ms
コード長 628 bytes
コンパイル時間 1,614 ms
コンパイル使用メモリ 48,836 KB
実行使用メモリ 35,408 KB
最終ジャッジ日時 2023-08-30 07:14:55
合計ジャッジ時間 43,381 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 91 ms
31,008 KB
testcase_04 AC 3,702 ms
35,264 KB
testcase_05 AC 1,302 ms
33,896 KB
testcase_06 AC 1,550 ms
34,844 KB
testcase_07 AC 1,972 ms
35,112 KB
testcase_08 AC 2,550 ms
35,220 KB
testcase_09 AC 3,371 ms
35,320 KB
testcase_10 AC 3,338 ms
35,216 KB
testcase_11 AC 3,450 ms
35,288 KB
testcase_12 AC 3,534 ms
35,308 KB
testcase_13 AC 3,559 ms
35,196 KB
testcase_14 AC 3,541 ms
35,408 KB
testcase_15 AC 3,618 ms
35,236 KB
testcase_16 AC 1,533 ms
34,004 KB
testcase_17 AC 1,148 ms
33,628 KB
testcase_18 AC 589 ms
32,576 KB
testcase_19 AC 2,406 ms
34,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <algorithm>
#include <cstdio>
#define N 3000
using namespace std;
int memo[N][N];

int gcd(int x,int y){
	if(!y)return x;
	if(x<N&&y<N){
		if(memo[x][y])return memo[x][y];
		return memo[x][y]=gcd(y,x%y);
	}
	return gcd(y,x%y);
}
int lcm(int x,int y){return x/gcd(x,y)*y;}
int main(){
	int n,s=0;
	scanf("%d",&n);
	vector<pair<int,int> >v(n);
	for(int i=0;i<n;i++)scanf("%d",&v[i].second);
	for(int i=0;i<n-2;i++){
		for(int j=i+1;j<n;j++)v[j].first=lcm(v[i].second,v[j].second);
		sort(v.begin()+i+1,v.end());
	}
	for(int i=0;i<n;i++)printf(i<n-1?"%d ":"%d\n",v[i].second);
}
0