結果

問題 No.2457 Stampaholic (Easy)
ユーザー kotatsugamekotatsugame
提出日時 2023-09-01 22:11:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 147 ms / 4,000 ms
コード長 917 bytes
コンパイル時間 839 ms
コンパイル使用メモリ 73,648 KB
実行使用メモリ 7,660 KB
最終ジャッジ日時 2023-09-01 22:11:19
合計ジャッジ時間 3,031 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,404 KB
testcase_01 AC 138 ms
7,472 KB
testcase_02 AC 18 ms
7,476 KB
testcase_03 AC 4 ms
7,408 KB
testcase_04 AC 4 ms
7,500 KB
testcase_05 AC 144 ms
7,524 KB
testcase_06 AC 15 ms
7,484 KB
testcase_07 AC 4 ms
7,508 KB
testcase_08 AC 19 ms
7,644 KB
testcase_09 AC 12 ms
7,536 KB
testcase_10 AC 27 ms
7,420 KB
testcase_11 AC 38 ms
7,484 KB
testcase_12 AC 54 ms
7,420 KB
testcase_13 AC 74 ms
7,476 KB
testcase_14 AC 115 ms
7,656 KB
testcase_15 AC 144 ms
7,660 KB
testcase_16 AC 143 ms
7,476 KB
testcase_17 AC 147 ms
7,476 KB
testcase_18 AC 16 ms
7,480 KB
testcase_19 AC 3 ms
7,392 KB
testcase_20 AC 4 ms
7,500 KB
testcase_21 AC 9 ms
7,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<cassert>
#include<atcoder/modint>
using namespace std;
using mint=atcoder::modint998244353;
vector<int>f(int H,int K)
{
	vector<int>ret;
	if(H<=2*(K-1))
	{
		for(int i=1;i<=H;i++)
		{
			int l=max(1,i-K+1),r=min(i,H-K+1);
			ret.push_back(r-l+1);
		}
	}
	else
	{
		for(int i=1;i<K;i++)
		{
			ret.push_back(i);
			ret.push_back(i);
		}
		int r=H-2*(K-1);
		ret.push_back(-r);
	}
	return ret;
}
int H,W,N,K;
mint C[1<<20];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>H>>W>>N>>K;
	vector<int>h=f(H,K),w=f(W,K);
	for(int hi:h)for(int wi:w)
	{
		if(hi>=0)
		{
			if(wi>=0)C[hi*wi]++;
			else C[hi*K]-=wi;
		}
		else
		{
			if(wi>=0)C[K*wi]-=hi;
			else C[K*K]+=(long)hi*wi;
		}
	}
	mint ans=(long)H*W;
	mint t=(long)(H-K+1)*(W-K+1);
	mint invt=t.inv();
	for(int c=1;c<=K*K;c++)
	{
		ans-=(1-mint::raw(c)*invt).pow(N)*C[c];
	}
	cout<<ans.val()<<endl;
}
0