結果

問題 No.916 Encounter On A Tree
ユーザー ptotqptotq
提出日時 2019-10-26 00:08:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 196 ms / 2,000 ms
コード長 1,078 bytes
コンパイル時間 137 ms
コンパイル使用メモリ 10,980 KB
実行使用メモリ 28,680 KB
最終ジャッジ日時 2023-10-11 12:19:54
合計ジャッジ時間 8,251 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,800 KB
testcase_01 AC 16 ms
7,796 KB
testcase_02 AC 196 ms
28,508 KB
testcase_03 AC 186 ms
28,584 KB
testcase_04 AC 186 ms
28,604 KB
testcase_05 AC 184 ms
28,620 KB
testcase_06 AC 188 ms
28,508 KB
testcase_07 AC 184 ms
28,572 KB
testcase_08 AC 37 ms
10,724 KB
testcase_09 AC 61 ms
13,248 KB
testcase_10 AC 16 ms
7,808 KB
testcase_11 AC 16 ms
7,832 KB
testcase_12 AC 183 ms
28,568 KB
testcase_13 AC 183 ms
28,680 KB
testcase_14 AC 189 ms
28,488 KB
testcase_15 AC 184 ms
28,620 KB
testcase_16 AC 59 ms
13,396 KB
testcase_17 AC 186 ms
28,600 KB
testcase_18 AC 16 ms
7,868 KB
testcase_19 AC 184 ms
28,644 KB
testcase_20 AC 193 ms
28,604 KB
testcase_21 AC 184 ms
28,600 KB
testcase_22 AC 184 ms
28,624 KB
testcase_23 AC 191 ms
28,528 KB
testcase_24 AC 183 ms
28,500 KB
testcase_25 AC 194 ms
28,604 KB
testcase_26 AC 105 ms
18,272 KB
testcase_27 AC 103 ms
18,412 KB
testcase_28 AC 59 ms
13,256 KB
testcase_29 AC 186 ms
28,672 KB
testcase_30 AC 190 ms
28,620 KB
testcase_31 AC 192 ms
28,656 KB
testcase_32 AC 184 ms
28,568 KB
testcase_33 AC 101 ms
18,360 KB
testcase_34 AC 62 ms
13,380 KB
testcase_35 AC 38 ms
10,616 KB
testcase_36 AC 189 ms
28,676 KB
testcase_37 AC 192 ms
28,672 KB
testcase_38 AC 61 ms
13,384 KB
testcase_39 AC 185 ms
28,492 KB
testcase_40 AC 190 ms
28,636 KB
testcase_41 AC 15 ms
7,908 KB
testcase_42 AC 16 ms
7,904 KB
testcase_43 AC 16 ms
7,848 KB
testcase_44 AC 16 ms
7,852 KB
testcase_45 AC 37 ms
10,712 KB
testcase_46 AC 16 ms
7,956 KB
testcase_47 AC 16 ms
7,840 KB
testcase_48 AC 15 ms
7,976 KB
testcase_49 AC 16 ms
7,872 KB
testcase_50 AC 16 ms
7,792 KB
testcase_51 AC 16 ms
7,920 KB
testcase_52 AC 15 ms
7,812 KB
testcase_53 AC 15 ms
7,820 KB
testcase_54 AC 16 ms
7,832 KB
testcase_55 AC 16 ms
7,856 KB
testcase_56 AC 16 ms
8,260 KB
testcase_57 AC 16 ms
8,300 KB
testcase_58 AC 17 ms
8,488 KB
testcase_59 AC 18 ms
8,528 KB
testcase_60 AC 21 ms
8,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

d, l, r, k = map(int, input().split())
mod = 10**9 + 7
ans = 1
fac = [1]*(2**(d-1)+1)
for i in range(1, 2**(d-1)+1):
    fac[i] = (fac[i-1] * i) % mod
depth1, depth2 = -1, -1

for depth in range(d):
    i_l, i_r = 2**depth, 2**(depth+1)-1
    nodes = 2**depth
    if i_l <= l <= i_r:
        depth1 = depth
        nodes -= 1
    if i_l <= r <= i_r:
        depth2 = depth
        nodes -= 1

    ans = (ans * fac[nodes]) % mod

if depth1 != depth2:
    lca_depth = depth1 - (k - (depth2 - depth1)) // 2
    need_edge = (depth1 - lca_depth) * 2 + (depth2 - depth1)
    # print(depth1, depth2, lca_depth, need_edge)
    if (k - (depth2 - depth1)) % 2 == 1 or lca_depth < 0 or depth1 < lca_depth or k != need_edge:
        ans = 0
    else:
        ans = ans * pow(2, depth2 - lca_depth, mod) // (2 if lca_depth != depth1 else 1) * pow(2, depth1, mod) % mod
else:
    if k % 2 == 1 or (d-1)*2 < k:
        ans = 0
    else:
        nodes = 2 ** depth1
        unit = 2 ** (k//2)
        n = nodes // unit
        ans = ans * (pow(unit//2, 2, mod) * n) * 2 % mod

print(ans % mod)
0