結果
問題 | No.14 最小公倍数ソート |
ユーザー | mamekin |
提出日時 | 2015-01-11 22:45:57 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 4,549 ms / 5,000 ms |
コード長 | 1,101 bytes |
コンパイル時間 | 679 ms |
コンパイル使用メモリ | 91,444 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-09-03 23:33:50 |
合計ジャッジ時間 | 51,009 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 50 ms
4,380 KB |
testcase_04 | AC | 4,549 ms
4,380 KB |
testcase_05 | AC | 1,530 ms
4,380 KB |
testcase_06 | AC | 1,786 ms
4,380 KB |
testcase_07 | AC | 2,332 ms
4,380 KB |
testcase_08 | AC | 3,088 ms
4,376 KB |
testcase_09 | AC | 4,151 ms
4,380 KB |
testcase_10 | AC | 4,072 ms
4,380 KB |
testcase_11 | AC | 4,224 ms
4,380 KB |
testcase_12 | AC | 4,383 ms
4,376 KB |
testcase_13 | AC | 4,403 ms
4,376 KB |
testcase_14 | AC | 4,282 ms
4,376 KB |
testcase_15 | AC | 4,418 ms
4,384 KB |
testcase_16 | AC | 1,641 ms
4,376 KB |
testcase_17 | AC | 1,175 ms
4,376 KB |
testcase_18 | AC | 524 ms
4,376 KB |
testcase_19 | AC | 2,774 ms
4,380 KB |
ソースコード
#include <cstdio> #include <iostream> #include <sstream> #include <fstream> #include <iomanip> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <limits> #include <climits> #include <cfloat> #include <functional> using namespace std; int gcd(int a, int b){ while(b != 0){ int tmp = a % b; a = b; b = tmp; } return a; } int lcm(int a, int b){ return a / gcd(a, b) * b; } int main() { int n; cin >> n; vector<int> a(n); for(int i=0; i<n; ++i) cin >> a[i]; for(int i=0; i<n-1; ++i){ int k = -1; int minLcm = INT_MAX; for(int j=i+1; j<n; ++j){ int x = lcm(a[i], a[j]); if(x < minLcm || (x == minLcm && a[j] < a[k])){ k = j; minLcm = x; } } swap(a[i+1], a[k]); } cout << a[0]; for(int i=1; i<n; ++i) cout << ' ' << a[i]; cout << endl; return 0; }