結果

問題 No.1683 Robot Guidance
ユーザー rlangevinrlangevin
提出日時 2023-09-27 12:05:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 417 ms / 2,000 ms
コード長 971 bytes
コンパイル時間 374 ms
コンパイル使用メモリ 86,956 KB
実行使用メモリ 108,568 KB
最終ジャッジ日時 2023-09-27 12:06:05
合計ジャッジ時間 8,986 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
107,104 KB
testcase_01 AC 116 ms
107,208 KB
testcase_02 AC 124 ms
107,460 KB
testcase_03 AC 145 ms
108,412 KB
testcase_04 AC 134 ms
108,568 KB
testcase_05 AC 151 ms
108,260 KB
testcase_06 AC 191 ms
108,284 KB
testcase_07 AC 160 ms
108,356 KB
testcase_08 AC 350 ms
108,388 KB
testcase_09 AC 159 ms
108,284 KB
testcase_10 AC 246 ms
108,296 KB
testcase_11 AC 242 ms
108,536 KB
testcase_12 AC 343 ms
108,480 KB
testcase_13 AC 115 ms
107,428 KB
testcase_14 AC 281 ms
108,480 KB
testcase_15 AC 151 ms
108,344 KB
testcase_16 AC 116 ms
107,176 KB
testcase_17 AC 118 ms
107,184 KB
testcase_18 AC 117 ms
107,164 KB
testcase_19 AC 118 ms
107,200 KB
testcase_20 AC 115 ms
107,496 KB
testcase_21 AC 126 ms
107,380 KB
testcase_22 AC 119 ms
107,056 KB
testcase_23 AC 117 ms
107,104 KB
testcase_24 AC 417 ms
108,372 KB
testcase_25 AC 118 ms
107,172 KB
testcase_26 AC 119 ms
107,060 KB
testcase_27 AC 116 ms
107,232 KB
testcase_28 AC 118 ms
107,168 KB
testcase_29 AC 116 ms
107,228 KB
testcase_30 AC 118 ms
107,184 KB
testcase_31 AC 119 ms
107,256 KB
testcase_32 AC 120 ms
107,020 KB
testcase_33 AC 159 ms
108,416 KB
testcase_34 AC 157 ms
108,160 KB
testcase_35 AC 150 ms
108,340 KB
testcase_36 AC 153 ms
108,432 KB
testcase_37 AC 131 ms
107,760 KB
testcase_38 AC 136 ms
108,088 KB
testcase_39 AC 118 ms
107,128 KB
testcase_40 AC 118 ms
107,396 KB
権限があれば一括ダウンロードができます

ソースコード

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