結果
| 問題 | No.14 最小公倍数ソート |
| コンテスト | |
| ユーザー |
EmKjp
|
| 提出日時 | 2015-02-21 15:41:45 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2,555 ms / 5,000 ms |
| コード長 | 1,229 bytes |
| 記録 | |
| コンパイル時間 | 737 ms |
| コンパイル使用メモリ | 106,396 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2026-03-09 05:25:59 |
| 合計ジャッジ時間 | 28,821 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<numeric>
#include<functional>
#include<complex>
using namespace std;
#define BET(a,b,c) ((a)<=(b)&&(b)<(c))
#define FOR(i,n) for(int i=0,i##_end=(int(n));i<i##_end;i++)
#define SZ(x) (int)(x.size())
#define ALL(x) (x).begin(),(x).end()
#define MP make_pair
#define FOR_EACH(it,v) for(__typeof(v.begin()) it=v.begin(),it_end=v.end() ; it != it_end ; it++)
typedef vector<int> VI;
typedef vector<VI> VVI;
long long gcd (long long s , long long t) { return t ? gcd(t,s%t) : s ; }
long long lcm (long long s , long long t) { return s / gcd(s, t) * t; }
int main()
{
int n;
cin>>n;
VI a(n);
FOR(i,n) scanf("%d",&a[i]);
for(int i=0;i<n;i++){
int x = a[i];
long long minLcm = 1LL<<62;
for(int j=i+1;j<n;j++){
long long l = lcm(x, a[j]);
if(l < minLcm || (l == minLcm && a[i+1] > a[j])){
minLcm = l;
swap(a[i+1], a[j]);
}
}
}
FOR(i,n) printf("%s%d",i?" ":"",a[i]);
puts("");
return 0;
}
EmKjp