結果

問題 No.2457 Stampaholic (Easy)
ユーザー sotanishysotanishy
提出日時 2023-09-01 23:16:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,991 ms / 4,000 ms
コード長 1,064 bytes
コンパイル時間 655 ms
コンパイル使用メモリ 87,320 KB
実行使用メモリ 77,928 KB
最終ジャッジ日時 2023-09-01 23:16:39
合計ジャッジ時間 11,262 ms
ジャッジサーバーID
(参考情報)
judge14 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,460 KB
testcase_01 AC 761 ms
76,352 KB
testcase_02 AC 155 ms
76,676 KB
testcase_03 AC 77 ms
71,136 KB
testcase_04 AC 78 ms
71,452 KB
testcase_05 AC 809 ms
76,584 KB
testcase_06 AC 99 ms
76,516 KB
testcase_07 AC 77 ms
71,672 KB
testcase_08 AC 171 ms
76,564 KB
testcase_09 AC 131 ms
76,536 KB
testcase_10 AC 198 ms
76,532 KB
testcase_11 AC 274 ms
76,656 KB
testcase_12 AC 346 ms
76,448 KB
testcase_13 AC 427 ms
76,648 KB
testcase_14 AC 704 ms
76,680 KB
testcase_15 AC 756 ms
76,588 KB
testcase_16 AC 780 ms
76,536 KB
testcase_17 AC 2,991 ms
77,928 KB
testcase_18 AC 194 ms
76,756 KB
testcase_19 AC 81 ms
76,208 KB
testcase_20 AC 76 ms
71,272 KB
testcase_21 AC 106 ms
76,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

mod = 998244353
H, W, N, K = map(int, input().split())

if H > W:
    H, W = W, H

ans = 0
den = pow((H-K+1)*(W-K+1), mod-2, mod)
if (K-1)*2 <= H:
    ans += (H-2*(K-1))*(W-2*(K-1))*(1-pow(1-K*K*den, N, mod)) % mod
    for i in range(K-1):
        ans += 2*(W-2*(K-1))*(1-pow(1-K*(i+1)*den, N, mod)) % mod
        ans += 2*(H-2*(K-1))*(1-pow(1-K*(i+1)*den, N, mod)) % mod
    for i in range(K-1):
        for j in range(K-1):
            ans += 4*(1-pow(1-(i+1)*(j+1)*den, N, mod)) % mod
elif (K-1)*2 <= W:
    for i in range(H):
        h = max(0, min(i, H-K) - max(0, i-K+1) + 1)
        ans += (W-2*(K-1))*(1-pow(1-h*K*den, N, mod)) % mod
        for j in range(K-1):
            w = max(0, min(j, W-K) - max(0, j-K+1) + 1)
            ans += 2*(1-pow(1-h*w*den, N, mod)) % mod
else:
    for i in range(H):
        for j in range(W):
            h = max(0, min(i, H-K) - max(0, i-K+1) + 1)
            w = max(0, min(j, W-K) - max(0, j-K+1) + 1)
            ans += (1-pow(1-h*w*den, N, mod)) % mod


ans %= mod
print(ans)
0