結果

問題 No.2457 Stampaholic (Easy)
ユーザー 横山緑
提出日時 2025-04-05 15:46:42
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 140 ms / 4,000 ms
コード長 3,770 bytes
コンパイル時間 3,720 ms
コンパイル使用メモリ 280,084 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2025-04-05 15:46:48
合計ジャッジ時間 5,870 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 2 "template.hpp"
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
template <class T>
concept Streamable = requires(ostream os, T &x) { os << x; };
template <class mint>
concept is_modint = requires(mint &x) {
    { x.val() } -> std::convertible_to<int>;
};
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...)
#endif

template <Streamable T> void print_one(const T &value) { cout << value; }
template <is_modint T> void print_one(const T &value) { cout << value.val(); }
void print() { cout << '\n'; }
template <class T, class... Ts> void print(const T &a, const Ts &...b) {
    print_one(a);
    ((cout << ' ', print_one(b)), ...);
    cout << '\n';
}
template <ranges::range Iterable>
    requires(!Streamable<Iterable>)
void print(const Iterable &v) {
    for(auto it = v.begin(); it != v.end(); ++it) {
        if(it != v.begin())
            cout << " ";
        print_one(*it);
    }
    cout << '\n';
}
using ll = long long;
using vl = vector<ll>;
using vll = vector<vl>;
using P = pair<ll, ll>;
#define all(v) v.begin(), v.end()
#define UNIQUE(v) ranges::sort(v), v.erase(unique(all(v)), end(v))
template <typename T> inline bool chmax(T &a, T b) {
    return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
    return ((a > b) ? (a = b, true) : (false));
}
// https://trap.jp/post/1224/
template <class... T> constexpr auto min(T... a) {
    return min(initializer_list<common_type_t<T...>>{a...});
}
template <class... T> constexpr auto max(T... a) {
    return max(initializer_list<common_type_t<T...>>{a...});
}
template <class... T> void input(T &...a) { (cin >> ... >> a); }
template <class T> void input(vector<T> &a) {
    for(T &x : a)
        cin >> x;
}
#define INT(...)                                                               \
    int __VA_ARGS__;                                                           \
    input(__VA_ARGS__)
#define LL(...)                                                                \
    long long __VA_ARGS__;                                                     \
    input(__VA_ARGS__)
#define STR(...)                                                               \
    string __VA_ARGS__;                                                        \
    input(__VA_ARGS__)
#define REP1(a) for(ll i = 0; i < a; i++)
#define REP2(i, a) for(ll i = 0; i < a; i++)
#define REP3(i, a, b) for(ll i = a; i < b; i++)
#define REP4(i, a, b, c) for(ll i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, REP4, REP3, REP2, REP1)(__VA_ARGS__)
#define rep1(i, n) for(ll i = 1; i <= ((ll)n); ++i)

ll inf = 3e18;
vl dx = {1, -1, 0, 0};
vl dy = {0, 0, 1, -1};
#line 2 "/home/y_midori/cp/a.cpp"
#include <atcoder/modint>
using mint = atcoder::modint998244353;
void solve() {
    INT(h, w, n, k);
    mint ans = 0;
    int imax = min(k, h - k), jmax = min(k, w - k);
    mint linv = mint(mint(h - k + 1) * (w - k + 1)).inv();
    // 四隅
    for(int i = 1; i <= imax; ++i) {
        for(int j = 1; j <= jmax; ++j) {
            mint p = 1 - linv * i * j;
            ans += 4 * (1 - p.pow(n));
        }
    }
    mint hl = abs(h - 2 * k), wl = abs(w - 2 * k);
    mint hr = (h >= 2 * k ? k : h - k + 1), wr = (w >= 2 * k ? k : w - k + 1);
    // 中
    mint p = 1 - linv * hr * wr;
    ans += hl * wl * (1 - p.pow(n));
    // 上下
    for(int i = 1; i <= imax; ++i) {
        mint p = 1 - linv * i * wr;
        ans += 2 * wl * (1 - p.pow(n));
    }
    // 左右
    for(int j = 1; j <= jmax; ++j) {
        mint p = 1 - linv * j * hr;
        ans += 2 * hl * (1 - p.pow(n));
    }
    print(ans);
}
int main() { solve(); }
0