結果

問題 No.2683 Two Sheets
ユーザー nikoro256nikoro256
提出日時 2024-03-22 17:24:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 729 bytes
コンパイル時間 351 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 59,768 KB
最終ジャッジ日時 2024-03-22 17:24:49
合計ジャッジ時間 2,036 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,460 KB
testcase_01 AC 35 ms
53,460 KB
testcase_02 AC 35 ms
53,460 KB
testcase_03 AC 41 ms
59,588 KB
testcase_04 AC 41 ms
59,588 KB
testcase_05 AC 44 ms
59,640 KB
testcase_06 AC 42 ms
59,640 KB
testcase_07 AC 42 ms
59,768 KB
testcase_08 AC 41 ms
59,588 KB
testcase_09 AC 42 ms
59,640 KB
testcase_10 AC 45 ms
59,588 KB
testcase_11 AC 42 ms
59,640 KB
testcase_12 AC 40 ms
59,588 KB
testcase_13 AC 41 ms
59,512 KB
testcase_14 AC 37 ms
53,460 KB
testcase_15 AC 44 ms
59,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def extgcd(a, b):
    if b:
        d, y, x = extgcd(b, a % b)
        y -= (a // b) * x
        return d, x, y
    return a, 1, 0

#以下modinv
def mod_inv(a, m):
    g, x, y = extgcd(a, m)

    if g != 1:
        raise Exception()

    if x < 0:
        x += m

    return x

H,W,A,B=map(int,input().split())
Hm=0
p=998244353
for i in range(1,A+1):
    if 2*A-i>H:
        continue
    if i!=A:
        Hm+=i*(H-(2*A-i)+1)*2
    else:
        Hm+=i*(H-(2*A-i)+1)
    Hm%=p
Wm=0
for i in range(1,B+1):
    if 2*B-i>W:
        continue
    if i!=B:
        Wm+=i*(W-(2*B-i)+1)*2
    else:
        Wm+=i*(W-(2*B-i)+1)
    Wm%=p
ans=((H-A+1)*(W-B+1))**2%p*(A*B*2)%p
inv=mod_inv((((H-A+1)*(W-B+1))**2),p)
print((ans-Hm*Wm)%p*inv%p)
0