結果
| 問題 |
No.916 Encounter On A Tree
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-05-03 18:32:57 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 53 ms / 2,000 ms |
| コード長 | 673 bytes |
| コンパイル時間 | 124 ms |
| コンパイル使用メモリ | 82,700 KB |
| 実行使用メモリ | 67,828 KB |
| 最終ジャッジ日時 | 2024-07-02 14:56:11 |
| 合計ジャッジ時間 | 4,296 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 56 |
ソースコード
d,l,r,k = map(int,input().split())
mod = 10**9+7
ans = 0
depl = len(bin(l))-3
depr = len(bin(r))-3
fact = [1]*((1<<d)+1)
for i in range(2,(1<<d)+1):
fact[i] = fact[i-1]*i%mod
ans = 0
for i in range(d+1):
p = depl-i
if p < 0:
continue
dif = k-i
if dif < 0 or dif != depr-p:
continue
base = 1<<depl
if i:
base *= ((1<<depr-p) - (1<<depr-p)//2)
else:
base *= 1<<depr-p
base %= mod
for i in range(d):
cand = 1<<i
if i == depl:
cand -= 1
if i == depr:
cand -= 1
base *= fact[cand]
base %= mod
ans += base
ans %= mod
print(ans)