結果

問題 No.1683 Robot Guidance
ユーザー asumo0729asumo0729
提出日時 2021-09-17 23:16:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 746 ms / 2,000 ms
コード長 2,017 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 273,668 KB
最終ジャッジ日時 2023-09-12 09:19:17
合計ジャッジ時間 24,732 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 509 ms
271,120 KB
testcase_01 AC 510 ms
272,260 KB
testcase_02 AC 514 ms
272,720 KB
testcase_03 AC 536 ms
271,832 KB
testcase_04 AC 526 ms
272,624 KB
testcase_05 AC 543 ms
272,704 KB
testcase_06 AC 572 ms
272,504 KB
testcase_07 AC 548 ms
272,844 KB
testcase_08 AC 709 ms
272,884 KB
testcase_09 AC 545 ms
271,688 KB
testcase_10 AC 618 ms
272,780 KB
testcase_11 AC 616 ms
272,756 KB
testcase_12 AC 703 ms
273,484 KB
testcase_13 AC 510 ms
272,548 KB
testcase_14 AC 657 ms
273,668 KB
testcase_15 AC 552 ms
272,836 KB
testcase_16 AC 520 ms
272,380 KB
testcase_17 AC 512 ms
271,208 KB
testcase_18 AC 511 ms
273,232 KB
testcase_19 AC 516 ms
273,364 KB
testcase_20 AC 512 ms
273,236 KB
testcase_21 AC 511 ms
272,264 KB
testcase_22 AC 513 ms
272,148 KB
testcase_23 AC 518 ms
271,256 KB
testcase_24 AC 746 ms
271,732 KB
testcase_25 AC 518 ms
272,752 KB
testcase_26 AC 520 ms
271,432 KB
testcase_27 AC 523 ms
272,288 KB
testcase_28 AC 520 ms
271,368 KB
testcase_29 AC 518 ms
272,080 KB
testcase_30 AC 517 ms
272,628 KB
testcase_31 AC 519 ms
272,056 KB
testcase_32 AC 523 ms
271,984 KB
testcase_33 AC 522 ms
273,344 KB
testcase_34 AC 523 ms
273,148 KB
testcase_35 AC 524 ms
273,168 KB
testcase_36 AC 523 ms
272,004 KB
testcase_37 AC 520 ms
271,644 KB
testcase_38 AC 522 ms
272,768 KB
testcase_39 AC 519 ms
272,024 KB
testcase_40 AC 508 ms
271,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0