結果

問題 No.1683 Robot Guidance
ユーザー puznekopuzneko
提出日時 2021-11-13 00:11:43
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,927 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 116,316 KB
最終ジャッジ日時 2023-08-17 06:04:36
合計ジャッジ時間 28,143 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,420 KB
testcase_01 AC 73 ms
71,316 KB
testcase_02 AC 87 ms
76,460 KB
testcase_03 AC 334 ms
83,248 KB
testcase_04 AC 154 ms
78,840 KB
testcase_05 AC 219 ms
81,272 KB
testcase_06 AC 440 ms
87,760 KB
testcase_07 AC 376 ms
84,932 KB
testcase_08 AC 1,134 ms
112,800 KB
testcase_09 AC 391 ms
88,096 KB
testcase_10 AC 693 ms
97,440 KB
testcase_11 AC 572 ms
94,684 KB
testcase_12 AC 957 ms
109,764 KB
testcase_13 AC 664 ms
96,512 KB
testcase_14 AC 1,172 ms
114,380 KB
testcase_15 AC 899 ms
108,972 KB
testcase_16 AC 817 ms
102,752 KB
testcase_17 AC 331 ms
83,200 KB
testcase_18 AC 382 ms
83,432 KB
testcase_19 AC 92 ms
76,584 KB
testcase_20 AC 91 ms
76,504 KB
testcase_21 AC 93 ms
76,516 KB
testcase_22 AC 459 ms
84,764 KB
testcase_23 AC 854 ms
108,280 KB
testcase_24 AC 1,255 ms
116,316 KB
testcase_25 AC 866 ms
108,424 KB
testcase_26 AC 1,222 ms
116,168 KB
testcase_27 AC 1,243 ms
116,252 KB
testcase_28 AC 853 ms
108,312 KB
testcase_29 RE -
testcase_30 AC 850 ms
108,236 KB
testcase_31 AC 756 ms
104,428 KB
testcase_32 AC 760 ms
104,480 KB
testcase_33 AC 671 ms
100,716 KB
testcase_34 AC 682 ms
100,976 KB
testcase_35 AC 765 ms
104,760 KB
testcase_36 AC 780 ms
104,952 KB
testcase_37 AC 629 ms
98,796 KB
testcase_38 AC 638 ms
98,852 KB
testcase_39 AC 877 ms
108,568 KB
testcase_40 AC 73 ms
71,432 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())
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