結果
| 問題 |
No.1683 Robot Guidance
|
| コンテスト | |
| ユーザー |
asumo0729
|
| 提出日時 | 2021-09-17 23:16:17 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 680 ms / 2,000 ms |
| コード長 | 2,017 bytes |
| コンパイル時間 | 303 ms |
| コンパイル使用メモリ | 82,372 KB |
| 実行使用メモリ | 272,220 KB |
| 最終ジャッジ日時 | 2024-06-29 22:03:15 |
| 合計ジャッジ時間 | 22,024 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
ソースコード
import sys
from operator import itemgetter
from collections import defaultdict, deque
import heapq
import bisect
stdin=sys.stdin
sys.setrecursionlimit(10 ** 8)
ip=lambda: int(sp())
fp=lambda: float(sp())
lp=lambda:list(map(int,stdin.readline().split()))
sp=lambda:stdin.readline().rstrip()
Yp=lambda:print('Yes')
Np=lambda:print('No')
inf = 1 << 60
eps = 1e-9
sortkey = itemgetter(0)
mod = 10 ** 9 + 7
class Comb():
def __init__(self, N, mod):
self.N = N
self.mod = mod
self.fa = self.fa_fainv()[0]
self.fainv = self.fa_fainv()[1]
def fa_fainv(self):
fa = [1]
for i in range(1, self.N + 1):
fa.append(fa[-1] * i % self.mod)
fainv = [pow(fa[-1],self.mod - 2,self.mod)]
for i in range(1, self.N + 1)[::-1]:
fainv.append(fainv[-1] * i % self.mod)
fainv = fainv[::-1]
return fa, fainv
def calcu_comb(self, a, b):
if b == 0:
return 1
return self.fa[a] * self.fainv[a - b] * self.fainv[b] % self.mod
###############################################################
comb = Comb(2 * 10 ** 6 + 5, mod)
A, B, X, Y = lp()
x = (B + 2) // 2
y = B + 1- x
xp = (x + 1) // 2
xm = x - xp
yp = (y + 1) // 2
ym = y - yp
ans = 0
for i in range(A + 1):
x_move = i
y_move = A - i
if abs(X - x_move) % 2 != 0 or abs(Y - y_move) % 2 != 0 or x_move < abs(X) or y_move < abs(Y):
continue
now_xp = (x_move + X) // 2
now_xm = x_move - now_xp
now_yp = (y_move + Y) // 2
now_ym = y_move - now_yp
if now_xp > 0 and xp <= 0:
continue
if now_xm > 0 and xm <= 0:
continue
if now_yp > 0 and yp <= 0:
continue
if now_ym > 0 and ym <= 0:
continue
p = comb.calcu_comb(now_xp + xp - 1,xp - 1)
q = comb.calcu_comb(now_xm + xm - 1,xm - 1)
r = comb.calcu_comb(now_yp + yp - 1,yp - 1)
s = comb.calcu_comb(now_ym + ym - 1,ym - 1)
res = p * q * r * s % mod
ans += res
ans %= mod
print(ans)
asumo0729