結果
問題 | No.14 最小公倍数ソート |
ユーザー |
|
提出日時 | 2017-12-03 11:23:12 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 540 bytes |
コンパイル時間 | 2,318 ms |
コンパイル使用メモリ | 65,776 KB |
実行使用メモリ | 13,632 KB |
最終ジャッジ日時 | 2024-11-28 09:07:13 |
合計ジャッジ時間 | 72,333 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 TLE * 8 |
ソースコード
#include <iostream>#include <vector>#include <algorithm>using namespace std;int gcd(int x,int y){while(y!=0){int temp=x%y;x=y;y=temp;}return x;}int lcm(int x, int y){return x/gcd(x,y)*y;}int main(){int n;cin>>n;vector<pair<int,int> >a(n);for(int i=0;i<n;i++)cin>>a[i].second;for(int i=0;i<n;i++){for(int j=i+1;j<n;j++){a[j].first=lcm(a[i].second,a[j].second);}sort(a.begin()+i+1,a.end());}cout<<a[0].second;for(int i=1;i<n;i++)cout<<' '<<a[i].second;cout<<endl;return 0;}