結果

問題 No.916 Encounter On A Tree
ユーザー tpynerivertpyneriver
提出日時 2019-10-28 17:35:53
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 1,045 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 86,800 KB
実行使用メモリ 111,236 KB
最終ジャッジ日時 2023-10-12 23:06:50
合計ジャッジ時間 11,605 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 148 ms
111,104 KB
testcase_01 AC 152 ms
110,988 KB
testcase_02 AC 150 ms
110,820 KB
testcase_03 AC 154 ms
110,896 KB
testcase_04 AC 150 ms
110,988 KB
testcase_05 WA -
testcase_06 AC 149 ms
111,028 KB
testcase_07 AC 149 ms
110,908 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 155 ms
110,896 KB
testcase_11 AC 148 ms
110,988 KB
testcase_12 AC 147 ms
110,984 KB
testcase_13 AC 148 ms
111,020 KB
testcase_14 AC 150 ms
110,992 KB
testcase_15 AC 149 ms
110,876 KB
testcase_16 AC 148 ms
111,024 KB
testcase_17 WA -
testcase_18 AC 148 ms
110,816 KB
testcase_19 AC 148 ms
111,112 KB
testcase_20 AC 147 ms
110,892 KB
testcase_21 WA -
testcase_22 AC 147 ms
110,996 KB
testcase_23 WA -
testcase_24 AC 147 ms
111,032 KB
testcase_25 AC 149 ms
110,904 KB
testcase_26 AC 150 ms
110,896 KB
testcase_27 AC 148 ms
111,004 KB
testcase_28 AC 151 ms
110,796 KB
testcase_29 WA -
testcase_30 AC 147 ms
110,792 KB
testcase_31 AC 148 ms
110,900 KB
testcase_32 AC 148 ms
111,000 KB
testcase_33 AC 149 ms
110,904 KB
testcase_34 AC 151 ms
110,980 KB
testcase_35 AC 148 ms
111,232 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 145 ms
111,004 KB
testcase_40 WA -
testcase_41 AC 146 ms
111,040 KB
testcase_42 AC 155 ms
110,896 KB
testcase_43 AC 152 ms
111,024 KB
testcase_44 AC 148 ms
111,120 KB
testcase_45 AC 149 ms
110,820 KB
testcase_46 AC 152 ms
111,236 KB
testcase_47 AC 147 ms
111,076 KB
testcase_48 AC 147 ms
110,900 KB
testcase_49 AC 156 ms
111,152 KB
testcase_50 AC 148 ms
111,168 KB
testcase_51 WA -
testcase_52 WA -
testcase_53 AC 148 ms
111,028 KB
testcase_54 AC 146 ms
111,104 KB
testcase_55 AC 149 ms
110,816 KB
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline
mod = 10**9+7

def frac(limit):
    frac = [1]*limit
    for i in range(2,limit):
        frac[i] = i * frac[i-1]%mod
    fraci = [None]*limit
    fraci[-1] = pow(frac[-1], mod -2, mod)
    for i in range(-2, -limit-1, -1):
        fraci[i] = fraci[i+1] * (limit + i + 1) % mod
    return frac, fraci
frac, fraci = frac(1341398)

def check(dl, dr, D, K):
    if dl > dr:
        dl, dr = dr, dl
    
    dist = dr - dl
    if dist > K:
        return 0
    if (K - dist) % 2 == 1:
        return 0
    if dl - (K-dist)//2 < 1:
        return 0
    if dl == dr == 1:
        return 0
    
    par = dl - (K-dist)//2
    if dl == par:
        return 1
    if dl == dr:
        return pow(2, dr-par-1, mod) * pow(pow(2, dr-1, mod) -1, mod-2, mod)
    else:
        return pow(pow(2, par - 2, mod), mod-2, mod)
        
    

D, L, R, K = map(int, readline().split())

dl = L.bit_length()
dr = R.bit_length()

ans = 1
for i in range(D):
    ans = ans*frac[pow(2, i)]%mod

print(ans*check(dl, dr, D, K) %mod)
0