結果
| 問題 |
No.834 Random Walk Trip
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 20:48:10 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 669 bytes |
| コンパイル時間 | 182 ms |
| コンパイル使用メモリ | 81,708 KB |
| 実行使用メモリ | 75,316 KB |
| 最終ジャッジ日時 | 2025-06-12 20:50:11 |
| 合計ジャッジ時間 | 2,518 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 WA * 2 |
ソースコード
MOD = 10**9 + 7
MAX = 10**6 + 10
# Precompute factorials and inverse factorials modulo MOD
fact = [1] * (MAX)
for i in range(1, MAX):
fact[i] = fact[i-1] * i % MOD
inv_fact = [1] * (MAX)
inv_fact[MAX-1] = pow(fact[MAX-1], MOD-2, MOD)
for i in range(MAX-2, -1, -1):
inv_fact[i] = inv_fact[i+1] * (i+1) % MOD
def compute_combination(m, k):
if k < 0 or k > m:
return 0
return fact[m] * inv_fact[k] % MOD * inv_fact[m - k] % MOD
# Read input
import sys
input = sys.stdin.read().split()
N = int(input[0])
M = int(input[1])
if N == 1:
print(1)
elif N == 2:
print(pow(2, M-1, MOD))
else:
k = M // 2
print(compute_combination(M, k))
gew1fw