結果
| 問題 | No.14 最小公倍数ソート |
| コンテスト | |
| ユーザー |
yaoshimax
|
| 提出日時 | 2015-02-10 14:30:59 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 1,927 ms / 5,000 ms |
| コード長 | 959 bytes |
| 記録 | |
| コンパイル時間 | 858 ms |
| コンパイル使用メモリ | 107,992 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2026-03-08 22:03:55 |
| 合計ジャッジ時間 | 22,314 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;
int gcd( int a, int b){
if( a > b ) return gcd(b,a);
if( b%a==0 ) return a;
return gcd( b%a, a);
}
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; i++){
int maxVal = INT_MAX;
int nextInd = i+1;
for( int j = i+1; j<N; j++){
int val= a[i]*a[j]/gcd(a[i],a[j]);
if( val < maxVal || (val==maxVal && a[nextInd] > a[j])){
maxVal=val;
nextInd=j;
}
}
swap(a[i+1],a[nextInd]);
}
for( int i = 0 ; i <N; i++ )printf("%d ",a[i]);
printf("\n");
return 0;
}
yaoshimax