結果

問題 No.2683 Two Sheets
ユーザー timi
提出日時 2024-03-21 16:12:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 608 bytes
コンパイル時間 138 ms
コンパイル使用メモリ 82,328 KB
実行使用メモリ 66,432 KB
最終ジャッジ日時 2024-09-30 10:09:15
合計ジャッジ時間 1,653 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 4 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W,A,B=map(int, input().split())
mod=998244353
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m


p=0
for i in range(1,W+1):
  c=min(min(abs(1-i),abs(W-i))+1,B) 
  p+=c**2

q=0
for i in range(1,H+1):
  c=min(min(abs(1-i),abs(H-i))+1,A) 
  q+=c**2

c=(H-A+1)*(W-B+1)
cc=c*c%mod
ans=2*A*B-p*q*modinv(cc,mod)
print(ans%mod)
0