結果

問題 No.2457 Stampaholic (Easy)
ユーザー chineristACchineristAC
提出日時 2023-09-01 22:36:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,903 ms / 4,000 ms
コード長 1,758 bytes
コンパイル時間 641 ms
コンパイル使用メモリ 87,300 KB
実行使用メモリ 79,652 KB
最終ジャッジ日時 2023-09-01 22:37:02
合計ジャッジ時間 22,938 ms
ジャッジサーバーID
(参考情報)
judge16 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
74,712 KB
testcase_01 AC 798 ms
78,712 KB
testcase_02 AC 422 ms
79,276 KB
testcase_03 AC 114 ms
74,880 KB
testcase_04 AC 114 ms
74,396 KB
testcase_05 AC 2,833 ms
79,396 KB
testcase_06 AC 249 ms
79,652 KB
testcase_07 AC 111 ms
74,612 KB
testcase_08 AC 462 ms
79,080 KB
testcase_09 AC 304 ms
79,260 KB
testcase_10 AC 588 ms
79,232 KB
testcase_11 AC 775 ms
78,984 KB
testcase_12 AC 1,156 ms
79,228 KB
testcase_13 AC 1,480 ms
79,148 KB
testcase_14 AC 2,481 ms
79,104 KB
testcase_15 AC 2,753 ms
79,512 KB
testcase_16 AC 2,772 ms
79,572 KB
testcase_17 AC 2,903 ms
79,416 KB
testcase_18 AC 331 ms
79,224 KB
testcase_19 AC 154 ms
79,176 KB
testcase_20 AC 116 ms
74,672 KB
testcase_21 AC 239 ms
79,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random
from itertools import permutations
from collections import deque

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

mod = 998244353

def brute(H,W,N,K):
    inv = pow((H-K+1)*(W-K+1),mod-2,mod)


    ans = 0
    for i in range(H):
        for j in range(W):
            """
            h <= i < h+K and 0 <= h < H-K+1
            max(i-K+1,0) <= h <= min(i,H-K)
            """

            h = min(i,H-K) - max(i-K+1,0) + 1
            w = min(j,W-K) - max(j-K+1,0) + 1

            ans += 1 - pow(1-h*w*inv % mod,N,mod)
            ans %= mod

    return ans

def calc_const_h(H,W,N,K,h):
    inv = pow((H-K+1)*(W-K+1),mod-2,mod)
    ans = 0

    cosnt_W = W
    for j in range(K-1):
        w = min(j,W-K) - max(j-K+1,0) + 1
        cosnt_W -= 1
        ans += 1 - pow(1-h*w*inv,N,mod)
        ans %= mod

        if (W-1-j) < K-1:
            continue
        w = min(W-1-j,W-K) - max(W-1-j-K+1,0) + 1
        cosnt_W -= 1
        ans += 1 - pow(1-h*w*inv,N,mod)
        ans %= mod
    
    w = K
    ans += (1 - pow(1-h*w*inv,N,mod) % mod) * cosnt_W % mod
    ans %= mod
    return ans



def solve_easy(H,W,N,K):    
    
    inv = pow((H-K+1)*(W-K+1),mod-2,mod)
    ans = 0

    const_H = H

    for i in range(K-1):
        h = min(i,H-K) - max(i-K+1,0) + 1
        const_H -= 1
        ans += calc_const_h(H,W,N,K,h)
        ans %= mod

        if H-1-i < K-1:
            continue

        h = min(H-1-i,H-K) - max(H-1-i-K+1,0) + 1
        const_H -= 1
        ans += calc_const_h(H,W,N,K,h)
        ans %= mod
    
    h = K
    ans += const_H * calc_const_h(H,W,N,K,h) % mod
    ans %= mod
    
    return ans


    
    


H,W,N,K = mi()

print(solve_easy(H,W,N,K))


0