結果

問題 No.2683 Two Sheets
ユーザー 👑 rin204rin204
提出日時 2024-02-29 22:32:31
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 934 bytes
コンパイル時間 3,555 ms
コンパイル使用メモリ 248,144 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-29 22:32:35
合計ジャッジ時間 4,208 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#include "atcoder/modint.hpp"
using mint = atcoder::modint998244353;

int main() {
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    assert(1 <= a and a <= h and h <= 200000);
    assert(1 <= b and b <= w and w <= 200000);

    auto f = [&](int n, int k) -> mint {
        // return \sum_{i=0}^{n} i (k + i)
        return mint(n) * (n + 1) / 2 * mint(k) + mint(n) * (n + 1) * (2 * n + 1) / 6;
    };

    int l    = max(1, 2 * a - h);
    int r    = a - 1;
    mint row = mint(2) * (f(r, h - 2 * a + 1) - f(l - 1, h - 2 * a + 1));
    row += mint(a) * (h - a + 1);

    l        = max(1, 2 * b - w);
    r        = b - 1;
    mint col = mint(2) * (f(r, w - 2 * b + 1) - f(l - 1, w - 2 * b + 1));
    col += mint(b) * (w - b + 1);

    mint ans = row * col;
    ans /= mint(h - a + 1).pow(2) * mint(w - b + 1).pow(2);
    ans = mint(2) * a * b - ans;
    cout << ans.val() << endl;
}
0