結果
問題 | No.376 立方体のN等分 (2) |
ユーザー | FF256grhy |
提出日時 | 2016-06-07 11:01:59 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,213 bytes |
コンパイル時間 | 914 ms |
コンパイル使用メモリ | 25,472 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-08 17:08:19 |
合計ジャッジ時間 | 2,870 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 1 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 3 ms
5,248 KB |
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 | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:125:21: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘LL’ {aka ‘long long int’} [-Wformat=] 125 | printf("%d %d\n", min - 3, n - 1); | ~^ ~~~~~ | | | | int LL {aka long long int} | %lld main.cpp:100:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 100 | scanf("%lld", &n); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <stdio.h> typedef long long int LL; LL n, factor[12], expo[12], length; void factorize() { LL m = n; for(LL i = 2; i * i <= m; i++) { if(m % i == 0) { factor[length] = i; while(m % i == 0) { m /= i; expo[length]++; } length++; } } if(m != 1) { factor[length] = m; expo[length]++; length++; } return; } int size() { int ans = 1; for(int i = 0; i < length; i++) { ans *= expo[i] + 1; } return ans; } LL val(int v) { LL ans = 1; for(int i = 0; i < length; i++) { for(int j = 0; j < v % (expo[i] + 1); j++) { ans *= factor[i]; } v /= (expo[i] + 1); } return ans; } void sort(LL* p, LL* q, int l, int r) { if(r - l < 2) { return; } int m = (l + r) / 2; sort(p, q, l, m); sort(p, q, m, r); int ll = l, rr = m, c = l; while(ll < m || rr < r) { bool flag; if(ll == m) { flag = false; } else if(rr == r) { flag = true; } else { flag = (p[ll] <= p[rr]); } if(flag) { q[c++] = p[ll++]; } else { q[c++] = p[rr++]; } } for(c = l; c < r; c++) { p[c] = q[c]; } return; } LL sqrt(LL x) { LL min = 0, max = 10000000; while(max - min > 1) { LL mid = (max + min) / 2; if(mid * mid <= x) { min = mid; } else { max = mid; } } return min; } LL cbrt(LL x) { LL min = 0, max = 100000; while(max - min > 1) { LL mid = (max + min) / 2; if(mid * mid * mid <= x) { min = mid; } else { max = mid; } } return min; } int find(LL* p, int s, LL x) { int min = 0, max = s; while(max - min > 1) { int mid = (max + min) / 2; if(p[mid] <= x) { min = mid; } else { max = mid; } } return min; } int main() { scanf("%lld", &n); factorize(); int s = size(); LL* p = new LL[s]; LL* q = new LL[s]; for(int i = 0; i < s; i++) { p[i] = val(i); } sort(p, q, 0, s); delete[] q; int cr = find(p, s, cbrt(n)); int min = p[cr] + n / p[cr] + 1; for(int i = cr; 0 <= i && p[i] + 2 * sqrt(n / p[i]) < min; i--) { for(int j = find(p, s, sqrt(n / p[i])); 0 <= j && p[i] + p[j] + n / p[i] / p[j] < min; j--) { if(n / p[i] % p[j] == 0) { int k = p[i] + p[j] + n / p[i] / p[j]; if(k < min) { min = k; } } } } printf("%d %d\n", min - 3, n - 1); return 0; }