結果
問題 | No.14 最小公倍数ソート |
ユーザー | k |
提出日時 | 2014-10-31 13:47:25 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 4,103 ms / 5,000 ms |
コード長 | 975 bytes |
コンパイル時間 | 932 ms |
コンパイル使用メモリ | 73,920 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-09 18:24:33 |
合計ジャッジ時間 | 47,824 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 59 ms
5,376 KB |
testcase_04 | AC | 4,103 ms
5,376 KB |
testcase_05 | AC | 1,370 ms
5,376 KB |
testcase_06 | AC | 1,646 ms
5,376 KB |
testcase_07 | AC | 2,135 ms
5,376 KB |
testcase_08 | AC | 2,813 ms
5,376 KB |
testcase_09 | AC | 3,771 ms
5,376 KB |
testcase_10 | AC | 3,735 ms
5,376 KB |
testcase_11 | AC | 3,854 ms
5,376 KB |
testcase_12 | AC | 4,013 ms
5,376 KB |
testcase_13 | AC | 4,069 ms
5,376 KB |
testcase_14 | AC | 3,885 ms
5,376 KB |
testcase_15 | AC | 4,047 ms
5,376 KB |
testcase_16 | AC | 1,628 ms
5,376 KB |
testcase_17 | AC | 1,194 ms
5,376 KB |
testcase_18 | AC | 564 ms
5,376 KB |
testcase_19 | AC | 2,646 ms
5,376 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:32:41: warning: format ‘%llu’ expects argument of type ‘long long unsigned int*’, but argument 2 has type ‘ll*’ {aka ‘long unsigned int*’} [-Wformat=] 32 | for (int i = 0; i < n; i++) scanf("%llu", &a[i]); | ~~~^ ~~~~~ | | | | | ll* {aka long unsigned int*} | long long unsigned int* | %lu main.cpp:35:15: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 2 has type ‘ll’ {aka ‘long unsigned int’} [-Wformat=] 35 | printf ("%llu ", a[0]); | ~~~^ ~~~~ | | | | | ll {aka long unsigned int} | long long unsigned int | %lu main.cpp:46:17: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 2 has type ‘ll’ {aka ‘long unsigned int’} [-Wformat=] 46 | printf ("%llu ", a[p]); | ~~~^ ~~~~ | | | | | ll {aka long unsigned int} | long long unsigned int | %lu main.cpp:32:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 32 | for (int i = 0; i < n; i++) scanf("%llu", &a[i]); | ~~~~~^~~~~~~~~~~~~~~
ソースコード
#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++) { if (p != -1 && mini < a[j]) break; ll t = lcm(a[i], a[j]); 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]); sort(a+i+2, a+n); } }