結果

問題 No.2683 Two Sheets
ユーザー flygonflygon
提出日時 2024-03-20 22:17:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 986 bytes
コンパイル時間 478 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 76,024 KB
最終ジャッジ日時 2024-03-20 22:17:22
合計ジャッジ時間 1,859 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
55,724 KB
testcase_01 AC 43 ms
55,724 KB
testcase_02 AC 43 ms
55,724 KB
testcase_03 AC 63 ms
72,612 KB
testcase_04 AC 53 ms
64,176 KB
testcase_05 AC 81 ms
76,024 KB
testcase_06 AC 75 ms
75,768 KB
testcase_07 AC 64 ms
72,580 KB
testcase_08 AC 63 ms
70,564 KB
testcase_09 AC 50 ms
61,540 KB
testcase_10 AC 66 ms
72,620 KB
testcase_11 AC 88 ms
75,896 KB
testcase_12 AC 53 ms
64,172 KB
testcase_13 AC 50 ms
61,548 KB
testcase_14 AC 44 ms
55,724 KB
testcase_15 AC 70 ms
73,060 KB
権限があれば一括ダウンロードができます

ソースコード

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