結果

問題 No.2683 Two Sheets
ユーザー 👑 timitimi
提出日時 2024-03-21 16:12:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 608 bytes
コンパイル時間 332 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 66,104 KB
最終ジャッジ日時 2024-03-21 16:12:57
合計ジャッジ時間 2,190 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 50 ms
64,040 KB
testcase_03 AC 60 ms
66,104 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 59 ms
66,104 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 62 ms
66,104 KB
testcase_13 WA -
testcase_14 AC 51 ms
61,956 KB
testcase_15 WA -
権限があれば一括ダウンロードができます

ソースコード

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