結果

問題 No.1683 Robot Guidance
ユーザー puznekopuzneko
提出日時 2021-11-13 00:13:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,251 ms / 2,000 ms
コード長 1,972 bytes
コンパイル時間 375 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 116,268 KB
最終ジャッジ日時 2023-08-17 06:13:36
合計ジャッジ時間 25,622 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,404 KB
testcase_01 AC 75 ms
71,420 KB
testcase_02 AC 88 ms
76,480 KB
testcase_03 AC 334 ms
83,076 KB
testcase_04 AC 154 ms
79,004 KB
testcase_05 AC 217 ms
81,260 KB
testcase_06 AC 441 ms
87,912 KB
testcase_07 AC 372 ms
84,944 KB
testcase_08 AC 1,131 ms
113,124 KB
testcase_09 AC 389 ms
88,192 KB
testcase_10 AC 689 ms
97,444 KB
testcase_11 AC 568 ms
94,412 KB
testcase_12 AC 950 ms
109,740 KB
testcase_13 AC 75 ms
71,424 KB
testcase_14 AC 1,166 ms
114,168 KB
testcase_15 AC 897 ms
108,976 KB
testcase_16 AC 813 ms
102,816 KB
testcase_17 AC 330 ms
83,032 KB
testcase_18 AC 382 ms
83,528 KB
testcase_19 AC 93 ms
76,556 KB
testcase_20 AC 91 ms
76,488 KB
testcase_21 AC 94 ms
76,592 KB
testcase_22 AC 458 ms
84,728 KB
testcase_23 AC 844 ms
108,228 KB
testcase_24 AC 1,251 ms
116,100 KB
testcase_25 AC 865 ms
108,512 KB
testcase_26 AC 1,220 ms
116,024 KB
testcase_27 AC 1,242 ms
116,268 KB
testcase_28 AC 849 ms
108,224 KB
testcase_29 AC 73 ms
71,348 KB
testcase_30 AC 850 ms
108,212 KB
testcase_31 AC 757 ms
104,380 KB
testcase_32 AC 761 ms
104,508 KB
testcase_33 AC 671 ms
100,868 KB
testcase_34 AC 685 ms
101,152 KB
testcase_35 AC 767 ms
104,788 KB
testcase_36 AC 779 ms
104,844 KB
testcase_37 AC 631 ms
98,948 KB
testcase_38 AC 643 ms
99,020 KB
testcase_39 AC 868 ms
108,316 KB
testcase_40 AC 72 ms
71,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def powmod(n,pow,mod):
    val = 1
    while pow > 0:
        if pow & 1:
            val = (val * n) % mod
        pow = pow >> 1
        n = (n * n) % mod
    return val

n, m, x, y = map(int, input().split())
if (n < x) | (n < y):
    print(0)
    exit()
p = 10 ** 9 + 7
kaijo = [1 for i in range(n+m//2+2)]
invkaijo = [1 for i in range(n+m//2+2)]
for i in range(1,n+m//2+2):
    kaijo[i] = kaijo[i-1] * i % p
    invkaijo[i] = powmod(kaijo[i],p-2,p)

pmnum = [m // 4 for i in range(4)]
for i in range(m%4+1):
    pmnum[i] += 1

xans = [0 for i in range(n+1)]
yans = [0 for i in range(n+1)]

if x >= 0:
    if pmnum[2] >= 1:
        for i in range((n-x)//2+1):
            xans[x+i*2] = kaijo[x+i+pmnum[0]-1] * invkaijo[x+i] % p * invkaijo[pmnum[0]-1] % p
            xans[x+i*2] = xans[x+i*2] * kaijo[i+pmnum[2]-1] % p * invkaijo[i] % p * invkaijo[pmnum[2]-1] % p
    else:
        xans[x] = 1
else:
    x = -x
    if pmnum[2] >= 1:
        for i in range((n-x)//2+1):
            xans[x+i*2] = kaijo[x+i+pmnum[2]-1] * invkaijo[x+i] % p * invkaijo[pmnum[2]-1] % p
            xans[x+i*2] = xans[x+i*2] * kaijo[i+pmnum[0]-1] % p * invkaijo[i] % p * invkaijo[pmnum[0]-1] % p

if pmnum[1] >= 1:
    if y >= 0:
        if pmnum[3] >= 1:
            for i in range((n-y)//2+1):
                yans[y+i*2] = kaijo[y+i+pmnum[1]-1] * invkaijo[y+i] % p * invkaijo[pmnum[1]-1] % p
                yans[y+i*2] = yans[y+i*2] * kaijo[i+pmnum[3]-1] % p * invkaijo[i] % p * invkaijo[pmnum[3]-1] % p
        else:
            yans[y] = 1
    else:
        y = -y
        if pmnum[3] >= 1:
            for i in range((n-y)//2+1):
                yans[y+i*2] = kaijo[y+i+pmnum[3]-1] * invkaijo[y+i] % p * invkaijo[pmnum[3]-1] % p
                yans[y+i*2] = yans[y+i*2] * kaijo[i+pmnum[1]-1] % p * invkaijo[i] % p * invkaijo[pmnum[1]-1] % p
else:
    if y == 0:
        yans[0] = 1

ans = 0
for i in range(n+1):
    ans = (ans + xans[i] * yans[n-i] % p) % p

print("{}".format(ans))
0