結果

問題 No.916 Encounter On A Tree
ユーザー maspymaspy
提出日時 2020-02-27 14:48:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,419 bytes
コンパイル時間 207 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 85,320 KB
最終ジャッジ日時 2024-04-21 16:59:22
合計ジャッジ時間 39,768 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 509 ms
44,432 KB
testcase_01 AC 514 ms
44,296 KB
testcase_02 AC 510 ms
44,040 KB
testcase_03 AC 638 ms
85,104 KB
testcase_04 AC 511 ms
44,296 KB
testcase_05 AC 639 ms
85,188 KB
testcase_06 AC 522 ms
44,040 KB
testcase_07 AC 636 ms
84,788 KB
testcase_08 AC 631 ms
85,172 KB
testcase_09 AC 619 ms
84,628 KB
testcase_10 AC 514 ms
43,912 KB
testcase_11 AC 630 ms
85,252 KB
testcase_12 AC 522 ms
44,552 KB
testcase_13 AC 626 ms
84,564 KB
testcase_14 WA -
testcase_15 AC 646 ms
85,120 KB
testcase_16 AC 524 ms
44,232 KB
testcase_17 AC 621 ms
84,816 KB
testcase_18 AC 625 ms
84,596 KB
testcase_19 AC 623 ms
85,052 KB
testcase_20 AC 511 ms
44,300 KB
testcase_21 AC 620 ms
85,184 KB
testcase_22 AC 518 ms
44,552 KB
testcase_23 AC 628 ms
84,664 KB
testcase_24 AC 513 ms
43,916 KB
testcase_25 AC 623 ms
84,576 KB
testcase_26 AC 516 ms
43,912 KB
testcase_27 AC 621 ms
85,124 KB
testcase_28 AC 516 ms
44,436 KB
testcase_29 AC 617 ms
85,320 KB
testcase_30 AC 516 ms
44,424 KB
testcase_31 AC 513 ms
43,916 KB
testcase_32 AC 512 ms
44,424 KB
testcase_33 AC 515 ms
44,560 KB
testcase_34 AC 619 ms
84,940 KB
testcase_35 AC 618 ms
84,580 KB
testcase_36 AC 619 ms
84,640 KB
testcase_37 AC 624 ms
84,740 KB
testcase_38 AC 619 ms
85,276 KB
testcase_39 AC 513 ms
43,924 KB
testcase_40 AC 622 ms
85,120 KB
testcase_41 AC 623 ms
84,648 KB
testcase_42 AC 628 ms
84,636 KB
testcase_43 AC 618 ms
84,748 KB
testcase_44 AC 516 ms
43,920 KB
testcase_45 AC 624 ms
84,692 KB
testcase_46 AC 512 ms
44,044 KB
testcase_47 AC 623 ms
85,172 KB
testcase_48 AC 516 ms
44,044 KB
testcase_49 AC 620 ms
84,648 KB
testcase_50 AC 626 ms
84,584 KB
testcase_51 AC 621 ms
85,124 KB
testcase_52 AC 619 ms
84,572 KB
testcase_53 AC 621 ms
84,732 KB
testcase_54 AC 515 ms
44,292 KB
testcase_55 AC 618 ms
84,660 KB
testcase_56 AC 619 ms
85,116 KB
testcase_57 AC 621 ms
85,208 KB
testcase_58 AC 623 ms
85,172 KB
testcase_59 AC 620 ms
85,272 KB
testcase_60 AC 620 ms
84,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


# %%
import numpy as np

# %%
MOD = 10 ** 9 + 7

# %%


def cumprod(A, MOD=MOD):
    L = len(A)
    Lsq = int(L**.5 + 1)
    A = np.resize(A, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        A[:, n] *= A[:, n - 1]
        A[:, n] %= MOD
    for n in range(1, Lsq):
        A[n] *= A[n - 1, -1]
        A[n] %= MOD
    return A.ravel()[:L]


def make_fact(U, MOD=MOD):
    x = np.arange(U, dtype=np.int64)
    x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64)
    x[0] = pow(int(fact[-1]), MOD - 2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    fact.flags.writeable = False
    fact_inv.flags.writeable = False
    return fact, fact_inv


# %%
D, L, R, K = map(int, read().split())

# %%
DL = L.bit_length()
DR = R.bit_length()
if DL > DR:
    DL, DR = DL, DR
lca_dep, r = divmod((DL + DR - K), 2)
if lca_dep < 0 or lca_dep > L or r:
    print(0)
    exit()

# %%
K, DL, DR, lca_dep
if lca_dep == DL:
    R_cand = 2 ** (DR - DL)
else:
    R_cand = 2 ** (DR - lca_dep - 1)
# %%
fact, fact_inv = make_fact(2 ** 20)
total = 1
for n in range(1, D + 1):
    total *= fact[2 ** (n - 1)]
    total %= MOD
total *= R_cand
total %= MOD
d = pow(2, DR - 1, MOD)
if DL == DR:
    d -= 1
total *= pow(d, MOD - 2, MOD)
total %= MOD
print(total)
0