結果
| 問題 |
No.916 Encounter On A Tree
|
| コンテスト | |
| ユーザー |
ptotq
|
| 提出日時 | 2019-10-25 22:52:28 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 725 bytes |
| コンパイル時間 | 257 ms |
| コンパイル使用メモリ | 12,416 KB |
| 実行使用メモリ | 21,784 KB |
| 最終ジャッジ日時 | 2024-09-13 06:32:08 |
| 合計ジャッジ時間 | 3,701 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 5 |
| other | AC * 2 TLE * 1 -- * 53 |
ソースコード
from math import factorial
d, l, r, k = map(int, input().split())
mod = 10**9 + 7
ans = 1
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 * factorial(nodes)) % mod
if depth1 != depth2:
if abs(depth1 - depth2) != k:
ans = 0
else:
ans = ans * 2**depth1 * 2**depth2 % 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)
ptotq