結果
問題 | No.376 立方体のN等分 (2) |
ユーザー | FF256grhy |
提出日時 | 2016-06-07 11:15:21 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 105 ms / 5,000 ms |
コード長 | 2,215 bytes |
コンパイル時間 | 523 ms |
コンパイル使用メモリ | 28,860 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-08-06 20:22:07 |
合計ジャッジ時間 | 2,582 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 1 ms
4,384 KB |
testcase_05 | AC | 1 ms
4,376 KB |
testcase_06 | AC | 1 ms
4,380 KB |
testcase_07 | AC | 1 ms
4,380 KB |
testcase_08 | AC | 4 ms
4,380 KB |
testcase_09 | AC | 1 ms
4,380 KB |
testcase_10 | AC | 3 ms
4,380 KB |
testcase_11 | AC | 6 ms
4,376 KB |
testcase_12 | AC | 2 ms
4,380 KB |
testcase_13 | AC | 1 ms
4,376 KB |
testcase_14 | AC | 2 ms
4,376 KB |
testcase_15 | AC | 9 ms
4,380 KB |
testcase_16 | AC | 6 ms
4,380 KB |
testcase_17 | AC | 1 ms
4,380 KB |
testcase_18 | AC | 8 ms
4,376 KB |
testcase_19 | AC | 2 ms
4,376 KB |
testcase_20 | AC | 2 ms
4,376 KB |
testcase_21 | AC | 5 ms
4,380 KB |
testcase_22 | AC | 1 ms
4,380 KB |
testcase_23 | AC | 6 ms
4,380 KB |
testcase_24 | AC | 6 ms
4,376 KB |
testcase_25 | AC | 1 ms
4,380 KB |
testcase_26 | AC | 7 ms
4,380 KB |
testcase_27 | AC | 74 ms
4,380 KB |
testcase_28 | AC | 2 ms
4,380 KB |
testcase_29 | AC | 3 ms
4,376 KB |
testcase_30 | AC | 1 ms
4,380 KB |
testcase_31 | AC | 22 ms
4,380 KB |
testcase_32 | AC | 74 ms
4,376 KB |
testcase_33 | AC | 105 ms
4,380 KB |
testcase_34 | AC | 53 ms
4,376 KB |
testcase_35 | AC | 53 ms
4,380 KB |
testcase_36 | AC | 104 ms
4,380 KB |
testcase_37 | AC | 104 ms
4,376 KB |
testcase_38 | AC | 29 ms
4,380 KB |
testcase_39 | AC | 2 ms
4,376 KB |
ソースコード
#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)); LL 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) { LL k = p[i] + p[j] + n / p[i] / p[j]; if(k < min) { min = k; } } } } printf("%lld %lld\n", min - 3, n - 1); return 0; }