結果

問題 No.2457 Stampaholic (Easy)
ユーザー KumaTachiRenKumaTachiRen
提出日時 2023-09-01 22:34:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 515 ms / 4,000 ms
コード長 2,108 bytes
コンパイル時間 7,746 ms
コンパイル使用メモリ 263,932 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-01 22:34:16
合計ジャッジ時間 7,277 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 140 ms
4,376 KB
testcase_02 AC 16 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 138 ms
4,376 KB
testcase_06 AC 8 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 17 ms
4,376 KB
testcase_09 AC 10 ms
4,380 KB
testcase_10 AC 25 ms
4,376 KB
testcase_11 AC 35 ms
4,380 KB
testcase_12 AC 51 ms
4,376 KB
testcase_13 AC 70 ms
4,376 KB
testcase_14 AC 110 ms
4,380 KB
testcase_15 AC 137 ms
4,376 KB
testcase_16 AC 137 ms
4,376 KB
testcase_17 AC 515 ms
4,376 KB
testcase_18 AC 22 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 6 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

struct Fast {
  Fast() {
    std::cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(10);
  }
} fast;

#define all(a) (a).begin(), (a).end()
#define contains(a, x) ((a).find(x) != (a).end())
#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (a); i--)
#define writejoin(s, a) rep(_i, 0, (a).size()) cout << (a)[_i] << (_i + 1 < (int)(a).size() ? s : "\n");
#define YN(b) cout << ((b) ? "YES" : "NO") << "\n";
#define Yn(b) cout << ((b) ? "Yes" : "No") << "\n";
#define yn(b) cout << ((b) ? "yes" : "no") << "\n";

using ll = long long;
using mint = modint998244353;

int main() {
  ll h, w, n, k;
  cin >> h >> w >> n >> k;

  mint prob = 1;
  prob *= h - k + 1;
  prob *= w - k + 1;
  prob = prob.inv();

  mint ans = 0;
  if (h <= 2 * k) {
    if (w <= 2 * k) {
      rep(i, 0, h) rep(j, 0, w) {
        ll x = min((ll)i, h - k) - max(0ll, i - k + 1) + 1;
        ll y = min((ll)j, w - k) - max(0ll, j - k + 1) + 1;
        ans += 1 - (1 - prob * x * y).pow(n);
      }
    } else {
      rep(i, 0, h) {
        ll x = min((ll)i, h - k) - max(0ll, i - k + 1) + 1;
        rep(y, 1, k) ans += (1 - (1 - prob * x * y).pow(n)) * 2;
        ans += (1 - (1 - prob * x * k).pow(n)) * (w - 2 * (k - 1));
      }
    }
  } else {
    if (w <= 2 * k) {
      swap(h, w);
      rep(i, 0, h) {
        ll x = min((ll)i, h - k) - max(0ll, i - k + 1) + 1;
        rep(y, 1, k) ans += (1 - (1 - prob * x * y).pow(n)) * 2;
        ans += (1 - (1 - prob * x * k).pow(n)) * (w - 2 * (k - 1));
      }
    } else {
      rep(x, 1, k) {
        rep(y, 1, k) ans += (1 - (1 - prob * x * y).pow(n)) * 2;
        ans += (1 - (1 - prob * x * k).pow(n)) * (w - 2 * (k - 1));
      }
      ans *= 2;
      {
        mint tmp = 0;
        rep(y, 1, k) tmp += (1 - (1 - prob * k * y).pow(n)) * 2;
        tmp += (1 - (1 - prob * k * k).pow(n)) * (w - 2 * (k - 1));
        ans += tmp * (h - 2 * (k - 1));
      }
    }
  }
  cout << ans.val() << "\n";
}
0