結果

問題 No.2457 Stampaholic (Easy)
ユーザー shobonvipshobonvip
提出日時 2023-09-01 22:51:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,237 ms / 4,000 ms
コード長 2,908 bytes
コンパイル時間 5,148 ms
コンパイル使用メモリ 275,688 KB
実行使用メモリ 191,068 KB
最終ジャッジ日時 2023-09-01 22:52:07
合計ジャッジ時間 23,704 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1,257 ms
50,696 KB
testcase_02 AC 202 ms
23,468 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2,237 ms
191,056 KB
testcase_06 AC 1,372 ms
147,432 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 222 ms
24,960 KB
testcase_09 AC 116 ms
15,612 KB
testcase_10 AC 413 ms
38,424 KB
testcase_11 AC 504 ms
51,664 KB
testcase_12 AC 882 ms
81,516 KB
testcase_13 AC 1,132 ms
100,988 KB
testcase_14 AC 1,951 ms
168,948 KB
testcase_15 AC 2,189 ms
191,068 KB
testcase_16 AC 2,162 ms
191,060 KB
testcase_17 AC 2,088 ms
175,556 KB
testcase_18 AC 148 ms
17,580 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 484 ms
65,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

int main(){
	int h, w, n, k; cin >> h >> w >> n >> k;
	mint r = mint(h-k+1) * (w-k+1);
	mint rinv = r.inv();
	set<pair<int,int>> s;
	mint ans = 0;
	{
		rep(i,0,k){
			rep(j,0,k){
				if (s.find(pair(i, j)) != s.end()) continue;
				s.insert(pair(i, j));
				ans += ((r - mint(min(h-k+1,i+1)) * (min(w-k+1,j+1))) * rinv).pow(n); 
			}
		}
	}
	{
		rep(i,0,k){
			rep(j,0,k){
				if (s.find(pair(h-1-i, j)) != s.end()) continue;
				s.insert(pair(h-1-i, j));
				ans += ((r - mint(min(h-k+1,i+1)) * (min(w-k+1,j+1))) * rinv).pow(n); 
			}
		}
	}
	{
		rep(i,0,k){
			rep(j,0,k){
				if (s.find(pair(i, w-1-j)) != s.end()) continue;
				s.insert(pair(i, w-1-j));
				ans += ((r - mint(min(h-k+1,i+1)) * (min(w-k+1,j+1))) * rinv).pow(n); 
			}
		}
	}
	{
		rep(i,0,k){
			rep(j,0,k){
				if (s.find(pair(h-1-i, w-1-j)) != s.end()) continue;
				s.insert(pair(h-1-i, w-1-j));
				ans += ((r - mint(min(h-k+1,i+1)) * (min(w-k+1,j+1))) * rinv).pow(n); 
			}
		}
	}
	set<int> s2;
	{
		mint hir = max(0,w - 2*k);
		rep(i,0,k){
			if (s2.find(i) != s2.end()) continue;
			s2.insert(i);
			ans += hir * ((r - mint(k) * min(h-k+1,i+1)) * rinv).pow(n);
		}
	}

	{
		mint hir = max(0,w - 2*k);
		rep(i,0,k){
			if (s2.find(h-1-i) != s2.end()) continue;
			s2.insert(h-1-i);
			ans += hir * ((r - mint(k) * min(h-k+1,i+1)) * rinv).pow(n);
		}
	}
	set<int> s3;
	
	{
		mint hir = max(0,h - 2*k);
		rep(i,0,k){
			if (s3.find(i) != s3.end()) continue;
			s3.insert(i);
			ans += hir * ((r - mint(k) * min(w-k+1,i+1)) * rinv).pow(n);
		}
	}
	{
		mint hir = max(0,h - 2*k);
		rep(i,0,k){
			if (s3.find(w-1-i) != s3.end()) continue;
			s3.insert(w-1-i);
			ans += hir * ((r - mint(k) * min(w-k+1,i+1)) * rinv).pow(n);
		}
	}

	{
		mint hir = mint(max(0,h - 2*k)) * (max(0,w - 2*k));
		ans += hir * ((r - mint(k) * k) * rinv).pow(n);
	}
	ans = mint(h) * w - ans;
	cout << ans.val() << '\n';
}

0