結果
問題 | No.916 Encounter On A Tree |
ユーザー | maspy |
提出日時 | 2020-02-27 14:50:25 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 582 ms / 2,000 ms |
コード長 | 1,420 bytes |
コンパイル時間 | 85 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 85,148 KB |
最終ジャッジ日時 | 2024-10-13 15:57:17 |
合計ジャッジ時間 | 34,204 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 479 ms
44,424 KB |
testcase_01 | AC | 468 ms
44,040 KB |
testcase_02 | AC | 473 ms
44,168 KB |
testcase_03 | AC | 568 ms
84,728 KB |
testcase_04 | AC | 468 ms
44,300 KB |
testcase_05 | AC | 572 ms
84,784 KB |
testcase_06 | AC | 479 ms
44,036 KB |
testcase_07 | AC | 568 ms
84,512 KB |
testcase_08 | AC | 569 ms
84,392 KB |
testcase_09 | AC | 572 ms
84,740 KB |
testcase_10 | AC | 467 ms
44,144 KB |
testcase_11 | AC | 560 ms
85,000 KB |
testcase_12 | AC | 473 ms
44,164 KB |
testcase_13 | AC | 563 ms
84,832 KB |
testcase_14 | AC | 461 ms
44,308 KB |
testcase_15 | AC | 561 ms
84,704 KB |
testcase_16 | AC | 460 ms
44,036 KB |
testcase_17 | AC | 558 ms
84,916 KB |
testcase_18 | AC | 572 ms
84,564 KB |
testcase_19 | AC | 574 ms
84,628 KB |
testcase_20 | AC | 464 ms
44,048 KB |
testcase_21 | AC | 562 ms
85,144 KB |
testcase_22 | AC | 469 ms
44,176 KB |
testcase_23 | AC | 551 ms
84,880 KB |
testcase_24 | AC | 458 ms
43,796 KB |
testcase_25 | AC | 566 ms
85,148 KB |
testcase_26 | AC | 463 ms
43,792 KB |
testcase_27 | AC | 558 ms
84,480 KB |
testcase_28 | AC | 454 ms
44,036 KB |
testcase_29 | AC | 557 ms
84,744 KB |
testcase_30 | AC | 466 ms
44,172 KB |
testcase_31 | AC | 463 ms
44,176 KB |
testcase_32 | AC | 462 ms
44,304 KB |
testcase_33 | AC | 463 ms
44,292 KB |
testcase_34 | AC | 566 ms
85,040 KB |
testcase_35 | AC | 564 ms
85,120 KB |
testcase_36 | AC | 562 ms
84,692 KB |
testcase_37 | AC | 582 ms
84,532 KB |
testcase_38 | AC | 571 ms
84,772 KB |
testcase_39 | AC | 466 ms
44,164 KB |
testcase_40 | AC | 562 ms
85,144 KB |
testcase_41 | AC | 563 ms
84,696 KB |
testcase_42 | AC | 567 ms
84,764 KB |
testcase_43 | AC | 555 ms
84,708 KB |
testcase_44 | AC | 460 ms
44,292 KB |
testcase_45 | AC | 550 ms
85,132 KB |
testcase_46 | AC | 459 ms
44,168 KB |
testcase_47 | AC | 557 ms
84,324 KB |
testcase_48 | AC | 524 ms
44,044 KB |
testcase_49 | AC | 559 ms
84,344 KB |
testcase_50 | AC | 561 ms
84,628 KB |
testcase_51 | AC | 561 ms
85,040 KB |
testcase_52 | AC | 561 ms
84,856 KB |
testcase_53 | AC | 556 ms
84,912 KB |
testcase_54 | AC | 469 ms
44,052 KB |
testcase_55 | AC | 560 ms
84,392 KB |
testcase_56 | AC | 575 ms
84,536 KB |
testcase_57 | AC | 562 ms
84,328 KB |
testcase_58 | AC | 557 ms
84,792 KB |
testcase_59 | AC | 567 ms
84,896 KB |
testcase_60 | AC | 562 ms
84,540 KB |
ソースコード
#!/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)