結果
問題 | No.916 Encounter On A Tree |
ユーザー | もりを |
提出日時 | 2019-10-25 23:24:04 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 323 ms / 2,000 ms |
コード長 | 2,519 bytes |
コンパイル時間 | 1,641 ms |
コンパイル使用メモリ | 170,316 KB |
実行使用メモリ | 19,804 KB |
最終ジャッジ日時 | 2024-09-13 08:53:54 |
合計ジャッジ時間 | 5,353 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 16 ms
19,584 KB |
testcase_01 | AC | 17 ms
19,592 KB |
testcase_02 | AC | 16 ms
19,584 KB |
testcase_03 | AC | 17 ms
19,700 KB |
testcase_04 | AC | 17 ms
19,584 KB |
testcase_05 | AC | 17 ms
19,712 KB |
testcase_06 | AC | 55 ms
19,664 KB |
testcase_07 | AC | 17 ms
19,584 KB |
testcase_08 | AC | 23 ms
19,712 KB |
testcase_09 | AC | 30 ms
19,584 KB |
testcase_10 | AC | 17 ms
19,616 KB |
testcase_11 | AC | 17 ms
19,584 KB |
testcase_12 | AC | 141 ms
19,620 KB |
testcase_13 | AC | 137 ms
19,584 KB |
testcase_14 | AC | 23 ms
19,584 KB |
testcase_15 | AC | 23 ms
19,604 KB |
testcase_16 | AC | 16 ms
19,712 KB |
testcase_17 | AC | 50 ms
19,700 KB |
testcase_18 | AC | 17 ms
19,584 KB |
testcase_19 | AC | 17 ms
19,584 KB |
testcase_20 | AC | 16 ms
19,584 KB |
testcase_21 | AC | 323 ms
19,584 KB |
testcase_22 | AC | 17 ms
19,584 KB |
testcase_23 | AC | 291 ms
19,584 KB |
testcase_24 | AC | 16 ms
19,684 KB |
testcase_25 | AC | 17 ms
19,608 KB |
testcase_26 | AC | 16 ms
19,760 KB |
testcase_27 | AC | 16 ms
19,616 KB |
testcase_28 | AC | 16 ms
19,592 KB |
testcase_29 | AC | 21 ms
19,624 KB |
testcase_30 | AC | 16 ms
19,804 KB |
testcase_31 | AC | 2 ms
6,940 KB |
testcase_32 | AC | 2 ms
6,940 KB |
testcase_33 | AC | 2 ms
6,940 KB |
testcase_34 | AC | 16 ms
19,680 KB |
testcase_35 | AC | 16 ms
19,624 KB |
testcase_36 | AC | 17 ms
19,584 KB |
testcase_37 | AC | 19 ms
19,664 KB |
testcase_38 | AC | 88 ms
19,584 KB |
testcase_39 | AC | 2 ms
6,944 KB |
testcase_40 | AC | 316 ms
19,668 KB |
testcase_41 | AC | 16 ms
19,652 KB |
testcase_42 | AC | 16 ms
19,600 KB |
testcase_43 | AC | 16 ms
19,628 KB |
testcase_44 | AC | 16 ms
19,776 KB |
testcase_45 | AC | 17 ms
19,720 KB |
testcase_46 | AC | 17 ms
19,568 KB |
testcase_47 | AC | 17 ms
19,592 KB |
testcase_48 | AC | 2 ms
6,944 KB |
testcase_49 | AC | 16 ms
19,672 KB |
testcase_50 | AC | 16 ms
19,696 KB |
testcase_51 | AC | 17 ms
19,624 KB |
testcase_52 | AC | 16 ms
19,564 KB |
testcase_53 | AC | 16 ms
19,588 KB |
testcase_54 | AC | 17 ms
19,580 KB |
testcase_55 | AC | 17 ms
19,660 KB |
testcase_56 | AC | 17 ms
19,704 KB |
testcase_57 | AC | 17 ms
19,688 KB |
testcase_58 | AC | 17 ms
19,604 KB |
testcase_59 | AC | 19 ms
19,616 KB |
testcase_60 | AC | 24 ms
19,700 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using i64 = int_fast64_t; using ui64 = uint_fast64_t; #define REP(i, n) for (i64 (i) = 0; (i) < (n); ++(i)) #define FOR(i, a, b) for (i64 (i) = (a); (i) < (b); ++(i)) constexpr int MOD = (int)1e9 + 7; ui64 MOP(ui64 x, ui64 n, ui64 m = MOD) { ui64 r = 1; while (n > 0) { if (n & 1) (r *= x) %= m; (x *= x) %= m; n >>= 1; } return r; } int D, L, R, K; vector<ui64> fact, dep; ui64 dist(ui64 a, ui64 b) { vector<ui64> v1, v2; while (a > 0) { v1.emplace_back(a); a >>= 1; } while (b > 0) { v2.emplace_back(b); b >>= 1; } for (int i = 0; i < v1.size(); ++i) { for (int j = 0; j < v2.size(); ++j) { if (v1[i] == v2[j]) { return i + j; } } } return 0; } signed main() { cin >> D >> L >> R >> K; if (K > D * 2) { cout << 0 << endl; return 0; } dep.resize(D + 1); dep[0] = dep[1] = 1; REP(i, D - 1) dep[i + 2] = dep[i + 1] * 2; fact.resize(2100100); fact[0] = fact[1] = 1; REP(i, 2100108) fact[i + 2] = (fact[i + 1] * (i + 2)) % MOD; ui64 dl = 0, dr = 0; { int tmp = L; while (tmp > 0) { ++dl; tmp >>= 1; } tmp = R; while (tmp > 0) { ++dr; tmp >>= 1; } } ui64 res = 0; if (dl == dr) { if (K % 2 == 1) { cout << 0 << endl; return 0; } K >>= 1; res = dep[K]; REP(i, K) (res <<= 1) %= MOD; (res *= dep[dl - K]) %= MOD; for (int i = 1; i <= D; ++i) { if (i == dl) { res *= fact[dep[i] - 2]; } else { res *= fact[dep[i]]; } res %= MOD; } } else { int dif = dr - dl; if (K - dif % 2 == 1) { cout << 0 << endl; return 0; } int k = (K - dif) >> 1; { int x = 1 << (dl - 1); for (int y = (1 << (dr - 1)); y < (1 << dr); ++y) { if (dist(x, y) == K) ++res; } } (res *= dep[dl]) %= MOD; for (int i = 1; i <= D; ++i) { if (i == dl or i == dr) { res *= fact[dep[i] - 1]; } else { res *= fact[dep[i]]; } res %= MOD; } } cout << res << endl; }