結果

問題 No.2683 Two Sheets
ユーザー flygon
提出日時 2024-03-20 22:17:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 986 bytes
コンパイル時間 316 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 76,288 KB
最終ジャッジ日時 2024-09-30 08:13:47
合計ジャッジ時間 1,882 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd

h,w,a,b = map(int,input().split())
mod = 998244353
mn =  a
for i in range(a+1)[::-1]:
    if h-2*a+i >= 0:
        mn = i

six = pow(6, mod-2, mod)
two = pow(2, mod-2, mod)
def calc(x):
    tmp = x*(x+1)*(2*x+1)*six%mod + (h-2*a+1)*x*(x+1)*two%mod
    tmp%= mod
    return tmp
all = 0
for i in range(b+1):
    if w-2*b+i < 0: continue
    c = (w-(2*b-i)+1)*i
    tmp = c*(calc(a))
    if mn >= 1:
        tmp -= c*(calc(mn-1))
        tmp %= mod
    if i == b:
        tmp *= 2
        tmp -= i*a*(h-a+1)*(w-2*b+i+1)
    else:
        tmp *= 4
        tmp -= 2*i*a*(h-a+1)*(w-2*b+i+1)
    all += tmp
    all %= mod

tot = (a*b*2)*(h-a+1)*(w-b+1)*(h-a+1)*(w-b+1)
ans = (tot-all)*pow((h-a+1)*(w-b+1)*(h-a+1)*(w-b+1), mod-2, mod) % mod
ans %= mod
print(ans)


    
0