結果
問題 | No.14 最小公倍数ソート |
ユーザー | k |
提出日時 | 2014-10-31 13:35:18 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 941 bytes |
コンパイル時間 | 520 ms |
コンパイル使用メモリ | 73,324 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-08-28 23:50:55 |
合計ジャッジ時間 | 40,871 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
ソースコード
#include <vector> #include <queue> #include <deque> #include <stack> #include <algorithm> #include <functional> #include <iostream> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <cctype> #include <string> using namespace std; typedef uint64_t ll; ll gcd(ll a, ll b){ if(b==0)return a; else return gcd(b, a%b); } ll lcm(ll a, ll b){ return a / gcd(a,b) * b; } int main() { ll n; cin >> n; ll a[n]; for (int i = 0; i < n; i++) scanf("%llu", &a[i]); sort(a+1, a+n); printf ("%llu ", a[0]); for (int i = 0; i < n-1; i++) { ll mini = 1000000000; int p = -1; for (int j = i+1; j < n; j++) { ll t = lcm(a[i], a[j]); if (mini < a[j]) break; if (mini > t) p = j; if (p != -1 && mini == t && a[p] > a[j]) p = j; mini = min(mini, t); } printf ("%llu ", a[p]); swap(a[p], a[i+1]); } }