結果
問題 | No.14 最小公倍数ソート |
ユーザー |
![]() |
提出日時 | 2016-09-29 15:31:11 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 574 bytes |
コンパイル時間 | 652 ms |
コンパイル使用メモリ | 60,260 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-21 10:31:13 |
合計ジャッジ時間 | 66,979 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 TLE * 8 |
ソースコード
#include<iostream> #include<algorithm> using namespace std; #define NMAX 10000 typedef struct s{ int a,saisyo; } S; bool operator<(S a,S b){ return a.saisyo<b.saisyo||(a.saisyo==b.saisyo&&a.a<b.a); } int gcd(int a,int b){ if(a<b) swap(a,b); if(b==0) return a; else return gcd(b,a%b); } int main(){ int N; S a[NMAX]; cin>>N; for(int i=0;i<N;i++) cin>>a[i].a; for(int i=0;i<N-1;i++){ for(int j=i+1;j<N;j++){ a[j].saisyo=a[i].a*a[j].a/gcd(a[i].a,a[j].a); } sort(a+i+1,a+N); } for(int i=0;i<N-1;i++) cout<<a[i].a<<" "; cout<<a[N-1].a<<endl; }