結果

問題 No.1683 Robot Guidance
ユーザー 👑 tamatotamato
提出日時 2021-09-17 22:01:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 181 ms / 2,000 ms
コード長 1,882 bytes
コンパイル時間 634 ms
コンパイル使用メモリ 87,424 KB
実行使用メモリ 100,304 KB
最終ジャッジ日時 2023-09-12 07:33:16
合計ジャッジ時間 8,579 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 163 ms
99,712 KB
testcase_01 AC 151 ms
99,732 KB
testcase_02 AC 150 ms
99,704 KB
testcase_03 AC 164 ms
99,916 KB
testcase_04 AC 160 ms
100,000 KB
testcase_05 AC 163 ms
99,944 KB
testcase_06 AC 165 ms
99,964 KB
testcase_07 AC 165 ms
100,296 KB
testcase_08 AC 174 ms
99,920 KB
testcase_09 AC 159 ms
99,920 KB
testcase_10 AC 168 ms
100,304 KB
testcase_11 AC 169 ms
100,032 KB
testcase_12 AC 171 ms
100,000 KB
testcase_13 AC 149 ms
99,632 KB
testcase_14 AC 171 ms
100,152 KB
testcase_15 AC 160 ms
99,924 KB
testcase_16 AC 153 ms
100,204 KB
testcase_17 AC 150 ms
99,632 KB
testcase_18 AC 148 ms
99,956 KB
testcase_19 AC 151 ms
99,668 KB
testcase_20 AC 149 ms
99,592 KB
testcase_21 AC 147 ms
99,704 KB
testcase_22 AC 153 ms
99,976 KB
testcase_23 AC 156 ms
99,712 KB
testcase_24 AC 181 ms
99,916 KB
testcase_25 AC 151 ms
100,028 KB
testcase_26 AC 153 ms
99,728 KB
testcase_27 AC 159 ms
99,548 KB
testcase_28 AC 152 ms
99,868 KB
testcase_29 AC 157 ms
99,660 KB
testcase_30 AC 155 ms
99,592 KB
testcase_31 AC 149 ms
99,688 KB
testcase_32 AC 154 ms
99,960 KB
testcase_33 AC 150 ms
99,592 KB
testcase_34 AC 148 ms
99,520 KB
testcase_35 AC 155 ms
99,960 KB
testcase_36 AC 152 ms
99,580 KB
testcase_37 AC 151 ms
99,788 KB
testcase_38 AC 164 ms
100,064 KB
testcase_39 AC 147 ms
99,708 KB
testcase_40 AC 150 ms
99,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    # comb init
    # mod = 1000000007
    nmax = 10 ** 6 + 10  # change here
    fac = [0] * nmax
    finv = [0] * nmax
    inv = [0] * nmax
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1
    for i in range(2, nmax):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod

    def comb(n, r):
        if n < r:
            return 0
        else:
            return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod

    a, b, x, y = map(int, input().split())
    if (x + y)%2 != a % 2:
        print(0)
        exit()

    if b == 0:
        if a == x and y == 0:
            print(1)
        else:
            print(0)
        exit()
    if b == 1:
        if x < 0 or y < 0:
            print(0)
        elif a != x + y:
            print(0)
        else:
            print(1)
        exit()
    if b == 2:
        if y < 0:
            print(0)
        else:
            aa = a - y
            print(1)
        exit()

    ans = 0
    Z = (a - abs(x) - abs(y)) // 2
    xp = xn = yp = yn = (b+1) // 4
    if b%4 == 0:
        xp += 1
    elif b%4 == 1:
        xp += 1
        yp += 1
    elif b%4 == 2:
        xp += 1
        yp += 1
        xn += 1
    for zx in range(Z+1):
        zy = Z - zx
        nx = abs(x) + 2 * zx
        ny = abs(y) + 2 * zy
        nxp = (nx + x) // 2
        nxn = nx - nxp
        nyp = (ny + y) // 2
        nyn = ny - nyp
        tmp = 1
        tmp = (tmp * comb(xp + nxp - 1, xp-1))%mod
        tmp = (tmp * comb(xn + nxn - 1, xn - 1)) % mod
        tmp = (tmp * comb(yp + nyp - 1, yp - 1)) % mod
        tmp = (tmp * comb(yn + nyn - 1, yn - 1)) % mod
        ans = (ans + tmp)%mod
    print(ans)


if __name__ == '__main__':
    main()
0