結果

問題 No.1683 Robot Guidance
ユーザー rlangevin
提出日時 2023-09-27 12:05:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 316 ms / 2,000 ms
コード長 971 bytes
コンパイル時間 198 ms
コンパイル使用メモリ 82,252 KB
実行使用メモリ 107,648 KB
最終ジャッジ日時 2024-07-20 06:13:34
合計ジャッジ時間 6,776 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10 ** 9 + 7
n = 2 * 10 ** 6 + 5
fact = [1] * (n + 1)
invfact = [1] * (n + 1)
for i in range(1, n):
    fact[i + 1] = ((i+1) * fact[i]) % mod
invfact[n] = pow(fact[n], mod - 2, mod)
for i in range(n - 1, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % mod

def comb(n, r):
    if n < 0 or r < 0 or n - r < 0:
        return 0
    return fact[n] * invfact[r] * invfact[n - r] % mod


A, B, X, Y = map(int, input().split())
L = [0] * 4
if X >= 0:
    L[0] = X
else:
    L[2] = -X

if Y >= 0:
    L[1] = Y
else:
    L[3] = -Y



V = [B//4] * 4
for i in range(B%4 + 1):
    V[i] += 1

ans = 0
N = A - sum(L)
if N < 0 or N % 2:
    print(0)
    exit()

N //= 2

def f(L, temp, V):
    val = 1
    for i in range(4):
        a = L[i] + temp[i]
        if V[i] == a == 0:
            continue
        val *= comb(V[i] - 1 + a, a)
        val %= mod
    return val


for i in range(N + 1):
    temp = [i, N-i, i, N-i]
    ans += f(L, temp, V)
    ans %= mod

print(ans)
0