結果
| 問題 | No.14 最小公倍数ソート |
| コンテスト | |
| ユーザー |
myanta
|
| 提出日時 | 2017-05-02 10:16:54 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 3,867 ms / 5,000 ms |
| コード長 | 721 bytes |
| 記録 | |
| コンパイル時間 | 398 ms |
| コンパイル使用メモリ | 67,288 KB |
| 実行使用メモリ | 7,972 KB |
| 最終ジャッジ日時 | 2026-04-04 10:14:06 |
| 合計ジャッジ時間 | 43,243 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
struct a_t
{
int x, y;
};
int gcd(int a, int b)
{
int c;
while((c=a%b))
{
a=b;
b=c;
}
return b;
}
int lcm(int a, int b)
{
return a/gcd(a,b)*b;
}
bool cmp(const a_t& lhs, const a_t& rhs)
{
if(lhs.y!=rhs.y) return lhs.y<rhs.y;
return lhs.x<rhs.x;
}
int main(void)
{
int n, i, j;
vector<a_t> a;
while(scanf("%d", &n)==1)
{
a.resize(n);
for(i=0;i<n;i++)
{
scanf("%d", &a[i].x);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
a[j].y=lcm(a[i].x, a[j].x);
}
sort(a.begin()+i+1, a.end(), cmp);
}
for(i=0;i<n-1;i++)
{
printf("%d ", a[i].x);
}
printf("%d\n", a[i].x);
}
return 0;
}
myanta