結果

問題 No.2457 Stampaholic (Easy)
ユーザー rniyarniya
提出日時 2023-09-01 22:50:59
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,148 ms / 4,000 ms
コード長 2,424 bytes
コンパイル時間 2,278 ms
コンパイル使用メモリ 206,040 KB
最終ジャッジ日時 2025-02-16 17:08:06
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif
#include "atcoder/modint"
using namespace std;
typedef long long ll;
#define all(x) begin(x), end(x)
constexpr int INF = (1 << 30) - 1;
constexpr long long IINF = (1LL << 60) - 1;
constexpr int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
template <class T> istream& operator>>(istream& is, vector<T>& v) {
for (auto& x : v) is >> x;
return is;
}
template <class T> ostream& operator<<(ostream& os, const vector<T>& v) {
auto sep = "";
for (const auto& x : v) os << exchange(sep, " ") << x;
return os;
}
template <class T, class U = T> bool chmin(T& x, U&& y) { return y < x and (x = forward<U>(y), true); }
template <class T, class U = T> bool chmax(T& x, U&& y) { return x < y and (x = forward<U>(y), true); }
template <class T> void mkuni(vector<T>& v) {
sort(begin(v), end(v));
v.erase(unique(begin(v), end(v)), end(v));
}
template <class T> int lwb(const vector<T>& v, const T& x) { return lower_bound(begin(v), end(v), x) - begin(v); }
using mint = atcoder::modint998244353;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int H, W, N, K;
cin >> H >> W >> N >> K;
mint ans = mint(H) * W, tot = mint(H - K + 1) * (W - K + 1);
if (K - 1 <= H - K and K - 1 <= W - K)
ans -= mint(H - K - (K - 1) + 1) * (W - K - (K - 1) + 1) * (1 - mint(K) * K / tot).pow(N);
vector<int> xs, ys;
for (int i = 0; i < K - 1; i++) {
xs.emplace_back(i);
xs.emplace_back(H - 1 - i);
ys.emplace_back(i);
ys.emplace_back(W - 1 - i);
}
mkuni(xs);
mkuni(ys);
for (int& x : xs) {
int lx = max(0, x - K + 1), rx = min(H - K, x);
if (rx < lx) continue;
for (int& y : ys) {
int ly = max(0, y - K + 1), ry = min(W - K, y);
if (ry < ly) continue;
ans -= (1 - mint(rx - lx + 1) * (ry - ly + 1) / tot).pow(N);
}
}
for (int& x : xs) {
int lx = max(0, x - K + 1), rx = min(H - K, x);
if (K - 1 <= W - K) ans -= mint(W - K - (K - 1) + 1) * (1 - mint(rx - lx + 1) * K / tot).pow(N);
}
for (int& y : ys) {
int ly = max(0, y - K + 1), ry = min(W - K, y);
if (K - 1 <= H - K) ans -= mint(H - K - (K - 1) + 1) * (1 - mint(ry - ly + 1) * K / tot).pow(N);
}
cout << ans.val() << '\n';
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0