結果

問題 No.2683 Two Sheets
ユーザー 👑 rin204
提出日時 2024-02-29 22:32:31
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 934 bytes
コンパイル時間 3,042 ms
コンパイル使用メモリ 247,912 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-09-29 13:03:08
合計ジャッジ時間 3,481 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

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