結果
| 問題 |
No.14 最小公倍数ソート
|
| コンテスト | |
| ユーザー |
myanta
|
| 提出日時 | 2017-05-02 10:16:54 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 721 bytes |
| コンパイル時間 | 607 ms |
| コンパイル使用メモリ | 45,440 KB |
| 実行使用メモリ | 8,192 KB |
| 最終ジャッジ日時 | 2024-09-14 04:37:00 |
| 合計ジャッジ時間 | 6,986 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 TLE * 1 -- * 15 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:50:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
50 | scanf("%d", &a[i].x);
| ~~~~~^~~~~~~~~~~~~~~
ソースコード
#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