結果
問題 |
No.14 最小公倍数ソート
|
ユーザー |
![]() |
提出日時 | 2014-11-02 02:01:48 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 720 bytes |
コンパイル時間 | 1,577 ms |
コンパイル使用メモリ | 158,428 KB |
実行使用メモリ | 13,824 KB |
最終ジャッジ日時 | 2024-12-30 16:14:14 |
合計ジャッジ時間 | 91,584 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 6 TLE * 14 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:10:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 10 | for(int i=0;i<N;i++) scanf("%d", a+i); | ~~~~~^~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; inline ll lcm(ll a, ll b) { return a*b/__gcd(a,b); } int main() { int N; cin >> N; int a[N], res[N]; for(int i=0;i<N;i++) scanf("%d", a+i); res[0] = a[0]; int rcnt = 1; for(int i=0;i<N-1;i++) { ll mn = 1<<29; for(int j=i+1;j<N;j++) { mn = min(mn, lcm(res[i], a[j])); } int idx, raw = 1<<29; for(int j=i+1;j<N;j++) { if(mn == lcm(res[i], a[j])) { if(a[j] < raw) { raw = a[j]; idx = j; } } } swap(a[i+1], a[idx]); res[rcnt++] = raw; } for(int i=0;i<N;i++) { if(i) printf(" "); printf("%d", res[i]); } puts(""); return 0; }