結果

問題 No.916 Encounter On A Tree
ユーザー stngstng
提出日時 2022-08-14 21:44:19
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,299 bytes
コンパイル時間 580 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 75,900 KB
最終ジャッジ日時 2024-04-08 22:02:53
合計ジャッジ時間 5,241 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 65 ms
75,900 KB
testcase_03 AC 69 ms
75,900 KB
testcase_04 AC 65 ms
75,900 KB
testcase_05 WA -
testcase_06 AC 66 ms
75,900 KB
testcase_07 WA -
testcase_08 AC 45 ms
61,564 KB
testcase_09 AC 49 ms
63,612 KB
testcase_10 AC 38 ms
53,460 KB
testcase_11 AC 37 ms
53,460 KB
testcase_12 AC 65 ms
75,900 KB
testcase_13 AC 65 ms
75,900 KB
testcase_14 AC 65 ms
75,900 KB
testcase_15 AC 65 ms
75,900 KB
testcase_16 AC 49 ms
63,612 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 67 ms
75,900 KB
testcase_21 WA -
testcase_22 AC 65 ms
75,900 KB
testcase_23 WA -
testcase_24 AC 66 ms
75,868 KB
testcase_25 WA -
testcase_26 AC 54 ms
67,676 KB
testcase_27 WA -
testcase_28 AC 50 ms
63,612 KB
testcase_29 WA -
testcase_30 AC 66 ms
75,900 KB
testcase_31 AC 66 ms
75,900 KB
testcase_32 AC 66 ms
75,900 KB
testcase_33 AC 56 ms
67,708 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 65 ms
75,900 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 65 ms
75,900 KB
testcase_40 AC 66 ms
75,900 KB
testcase_41 AC 35 ms
53,460 KB
testcase_42 AC 37 ms
53,460 KB
testcase_43 AC 36 ms
53,460 KB
testcase_44 AC 36 ms
53,460 KB
testcase_45 AC 45 ms
61,564 KB
testcase_46 AC 36 ms
53,460 KB
testcase_47 AC 36 ms
53,460 KB
testcase_48 AC 36 ms
53,460 KB
testcase_49 AC 36 ms
53,460 KB
testcase_50 AC 36 ms
53,460 KB
testcase_51 AC 37 ms
53,460 KB
testcase_52 WA -
testcase_53 AC 38 ms
53,460 KB
testcase_54 AC 38 ms
53,460 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 AC 43 ms
59,464 KB
testcase_59 WA -
testcase_60 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

d,L,R,k = map(int,input().split())

MOD = 10**9+7
N = 2**d

fact = [1]*(N+1)
rfact = [1]*(N+1)
r = 1
for i in range(1, N+1):
    fact[i] = r = r * i % MOD
rfact[N] = r = pow(fact[N], MOD-2, MOD)
for i in range(N, 0, -1):
    rfact[i-1] = r = r * i % MOD

# nPk (mod MOD) を求める
def perm(n, k):
    return fact[n] * rfact[n-k] % MOD

rui = []
val = 1
for i in range(d):
    rui.append(val)
    if L >= val:
        lidx = i
    if R >= val:
        ridx = i
    val *= 2

ans = 1

f = False
if lidx == ridx:
    f = True
    if k % 2 != 0 or k > 2*lidx:
        print(0)
        exit()
else:
    if k != abs(lidx-ridx) and k != lidx+ridx:
        print(0)
        exit()

if f == True:
    for i in range(d):
        if i == lidx:
            tmp = pow(2,i,MOD)
            if tmp == 2:
                ans *= tmp*1*perm(tmp-2,tmp-2)
            else:
                ans *= tmp*2*perm(tmp-2,tmp-2)
            ans %= MOD
            continue
        tmp = pow(2,i,MOD)
        ans *= perm(tmp,tmp)
        ans %= MOD
    print(ans%MOD)
else:
    for i in range(d):
        if i == lidx:
            tmp = pow(2,i,MOD)
            ans *= perm(tmp-1,tmp-1)
            ans %= MOD
            continue
        tmp = pow(2,i,MOD)
        ans *= perm(tmp,tmp)
        ans %= MOD
    print(ans%MOD)
0