結果

問題 No.2683 Two Sheets
ユーザー nikoro256
提出日時 2024-03-22 17:24:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 729 bytes
コンパイル時間 245 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 59,776 KB
最終ジャッジ日時 2024-09-30 10:38:35
合計ジャッジ時間 1,744 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

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