結果

問題 No.14 最小公倍数ソート
ユーザー ytftytft
提出日時 2022-11-03 00:33:19
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,817 ms / 5,000 ms
コード長 455 bytes
コンパイル時間 2,679 ms
コンパイル使用メモリ 242,152 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-24 11:16:57
合計ジャッジ時間 34,290 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 31 ms
4,380 KB
testcase_04 AC 2,817 ms
4,380 KB
testcase_05 AC 939 ms
4,380 KB
testcase_06 AC 1,101 ms
4,376 KB
testcase_07 AC 1,438 ms
4,376 KB
testcase_08 AC 1,894 ms
4,380 KB
testcase_09 AC 2,576 ms
4,380 KB
testcase_10 AC 2,535 ms
4,380 KB
testcase_11 AC 2,624 ms
4,376 KB
testcase_12 AC 2,692 ms
4,380 KB
testcase_13 AC 2,730 ms
4,376 KB
testcase_14 AC 2,647 ms
4,376 KB
testcase_15 AC 2,736 ms
4,376 KB
testcase_16 AC 1,016 ms
4,380 KB
testcase_17 AC 724 ms
4,380 KB
testcase_18 AC 323 ms
4,376 KB
testcase_19 AC 1,716 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	scanf("%d",&N);
	int A[N];
	for(int i=0;i<N;++i){
		scanf("%d",&A[i]);
	}
	for(int i=0;i<N-2;++i){
		int minlcm=lcm(A[i],A[i+1]),index=i+1;
		for(int j=i+2;j<N;++j){
			int l=lcm(A[i],A[j]);
			if(l<minlcm){
				minlcm=l;
				index=j;
			}else if(l==minlcm&&A[index]>A[j]){
				index=j;
			}
		}
		swap(A[i+1],A[index]);
	}
	for(int i=0;i<N;++i){
		printf("%d ",A[i]);
	}
	printf("\n");
}
0