結果

問題 No.2457 Stampaholic (Easy)
ユーザー rniyarniya
提出日時 2023-09-01 22:50:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,151 ms / 4,000 ms
コード長 2,424 bytes
コンパイル時間 2,633 ms
コンパイル使用メモリ 210,012 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-01 22:51:24
合計ジャッジ時間 12,040 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 286 ms
4,376 KB
testcase_02 AC 122 ms
4,384 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1,135 ms
4,380 KB
testcase_06 AC 460 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 130 ms
4,380 KB
testcase_09 AC 74 ms
4,380 KB
testcase_10 AC 203 ms
4,380 KB
testcase_11 AC 287 ms
4,376 KB
testcase_12 AC 445 ms
4,380 KB
testcase_13 AC 610 ms
4,380 KB
testcase_14 AC 946 ms
4,380 KB
testcase_15 AC 1,151 ms
4,380 KB
testcase_16 AC 1,141 ms
4,376 KB
testcase_17 AC 1,071 ms
4,384 KB
testcase_18 AC 87 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 203 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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;
}
0