結果

問題 No.1683 Robot Guidance
ユーザー puznekopuzneko
提出日時 2021-11-13 00:11:43
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,927 bytes
コンパイル時間 199 ms
コンパイル使用メモリ 82,528 KB
実行使用メモリ 115,288 KB
最終ジャッジ日時 2024-05-04 12:59:57
合計ジャッジ時間 22,811 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
52,480 KB
testcase_01 AC 33 ms
52,480 KB
testcase_02 AC 43 ms
63,616 KB
testcase_03 AC 262 ms
81,792 KB
testcase_04 AC 107 ms
77,952 KB
testcase_05 AC 167 ms
80,128 KB
testcase_06 AC 357 ms
86,528 KB
testcase_07 AC 299 ms
83,968 KB
testcase_08 AC 971 ms
111,616 KB
testcase_09 AC 314 ms
86,956 KB
testcase_10 AC 597 ms
96,256 KB
testcase_11 AC 482 ms
93,448 KB
testcase_12 AC 822 ms
108,800 KB
testcase_13 AC 560 ms
95,692 KB
testcase_14 AC 1,009 ms
113,412 KB
testcase_15 AC 782 ms
107,840 KB
testcase_16 AC 686 ms
101,452 KB
testcase_17 AC 262 ms
82,184 KB
testcase_18 AC 309 ms
82,432 KB
testcase_19 AC 57 ms
68,224 KB
testcase_20 AC 56 ms
67,840 KB
testcase_21 AC 56 ms
67,328 KB
testcase_22 AC 396 ms
83,584 KB
testcase_23 AC 742 ms
107,120 KB
testcase_24 AC 1,109 ms
115,192 KB
testcase_25 AC 775 ms
107,372 KB
testcase_26 AC 1,074 ms
115,004 KB
testcase_27 AC 1,071 ms
115,288 KB
testcase_28 AC 721 ms
107,240 KB
testcase_29 RE -
testcase_30 AC 737 ms
107,188 KB
testcase_31 AC 641 ms
103,440 KB
testcase_32 AC 642 ms
103,308 KB
testcase_33 AC 557 ms
100,032 KB
testcase_34 AC 581 ms
99,788 KB
testcase_35 AC 663 ms
103,880 KB
testcase_36 AC 658 ms
103,760 KB
testcase_37 AC 525 ms
97,900 KB
testcase_38 AC 543 ms
97,756 KB
testcase_39 AC 745 ms
107,172 KB
testcase_40 AC 33 ms
54,060 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