結果

問題 No.1683 Robot Guidance
ユーザー neterukunneterukun
提出日時 2021-09-17 22:05:37
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,194 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 87,304 KB
実行使用メモリ 161,084 KB
最終ジャッジ日時 2023-09-12 07:44:16
合計ジャッジ時間 9,883 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 171 ms
161,084 KB
testcase_01 AC 168 ms
159,860 KB
testcase_02 AC 175 ms
160,476 KB
testcase_03 WA -
testcase_04 AC 187 ms
160,216 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 208 ms
160,356 KB
testcase_13 AC 177 ms
160,460 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 182 ms
160,504 KB
testcase_17 AC 175 ms
160,080 KB
testcase_18 AC 176 ms
159,924 KB
testcase_19 AC 176 ms
160,104 KB
testcase_20 AC 176 ms
160,248 KB
testcase_21 AC 184 ms
160,028 KB
testcase_22 AC 173 ms
160,244 KB
testcase_23 AC 178 ms
160,092 KB
testcase_24 WA -
testcase_25 AC 179 ms
160,260 KB
testcase_26 RE -
testcase_27 WA -
testcase_28 AC 176 ms
160,080 KB
testcase_29 AC 178 ms
160,108 KB
testcase_30 AC 178 ms
160,288 KB
testcase_31 AC 178 ms
160,216 KB
testcase_32 AC 180 ms
160,252 KB
testcase_33 AC 195 ms
160,228 KB
testcase_34 AC 202 ms
160,328 KB
testcase_35 AC 187 ms
160,104 KB
testcase_36 AC 188 ms
160,028 KB
testcase_37 AC 215 ms
160,824 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

class Combination:
    def __init__(self, n, MOD):
        self.f = [1]
        for i in range(1, n + 1):
            self.f.append(self.f[-1] * i % MOD)
        self.inv_f = [0] * (n + 1)
        self.inv_f[n] = pow(self.f[n], MOD - 2, MOD)
        for i in reversed(range(n)):
            self.inv_f[i] = self.inv_f[i + 1] * (i + 1) % MOD
        self.MOD = MOD

    def inv(self, k):
        """get inverse(k)"""
        return (self.inv_f[k] * self.f[k - 1]) % self.MOD

    def fact(self, k):
        """get k!"""
        return self.f[k]

    def inv_fact(self, k):
        """get inverse(k!)"""
        return self.inv_f[k]

    def perm(self, k, r):
        """get kPr"""
        if k < r:
            return 0
        return (self.f[k] * self.inv_f[k - r]) % self.MOD

    def comb(self, k, r):
        """get kCr"""
        if k < r:
            return 0
        return (self.f[k] * self.inv_f[k - r] % self.MOD
                * self.inv_f[r]) % self.MOD


def way4(ball, box):
    """ball: False / box: True / constraints: None
    -> ans = comb(box + ball - 1, ball)
    """
    if ball == 0 and box == 0:
        return 1
    return comb.comb(ball + box - 1, ball)

    # 区別するbox個の箱 -> 区別しない(box - 1)個の仕切に変換して解く


def solve(xp_cnt, xm_cnt, yp_cnt, ym_cnt):
    res = 1
    res = res * way4(xp_cnt, xp) % MOD
    res = res * way4(xm_cnt, xm) % MOD
    res = res * way4(yp_cnt, yp) % MOD
    res = res * way4(ym_cnt, ym) % MOD
    return res

a, b, x, y = map(int, input().split())
MOD = 10 ** 9 + 7
comb = Combination(10 ** 6 + 10, MOD)

bucket = [1, 0, 0, 0]
for i in range(b):
    i += 1
    bucket[i % 4] += 1
xp, yp, xm, ym = bucket


ans = 0
for i in range(a + 1):
    cntx = i
    cnty = a - i

    xp_cnt = (cntx + x)
    xm_cnt = (cntx - x)
    yp_cnt = (cnty + y)
    ym_cnt = (cnty - y)

    if xp_cnt % 2 == 1:
        continue
    if xm_cnt % 2 == 1 or xm_cnt < 0:
        continue
    if yp_cnt % 2 == 1:
        continue
    if ym_cnt % 2 == 1 or ym_cnt < 0:
        continue

    xp_cnt //= 2
    xm_cnt //= 2
    yp_cnt //= 2
    ym_cnt //= 2

    ans += solve(xp_cnt, xm_cnt, yp_cnt, ym_cnt)
    ans %= MOD

print(ans)
0