結果

問題 No.2683 Two Sheets
ユーザー tnakao0123tnakao0123
提出日時 2024-04-26 15:03:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,858 bytes
コンパイル時間 598 ms
コンパイル使用メモリ 47,440 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 15:03:03
合計ジャッジ時間 1,318 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2683.cc:  No.2683 Two Sheets - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const int MOD = 998244353;

/* typedef */

template<const int MOD>
struct MI {
  int v;
  MI(): v() {}
  MI(int _v): v(_v % MOD) { if (v < 0) v += MOD; }
  MI(long long _v): v(_v % MOD) { if (v < 0) v += MOD; }

  explicit operator int() const { return v; }
  
  MI operator+(const MI m) const { return MI(v + m.v); }
  MI operator-(const MI m) const { return MI(v + MOD - m.v); }
  MI operator*(const MI m) const { return MI((long long)v * m.v); }

  MI &operator+=(const MI m) { return (*this = *this + m); }
  MI &operator-=(const MI m) { return (*this = *this - m); }
  MI &operator*=(const MI m) { return (*this = *this * m); }

  bool operator==(const MI m) const { return v == m.v; }
  bool operator!=(const MI m) const { return v != m.v; }

  MI pow(int n) const {  // a^n % MOD
    MI pm = 1, a = *this;
    while (n > 0) {
      if (n & 1) pm *= a;
      a *= a;
      n >>= 1;
    }
    return pm;
  }

  MI inv() const { return pow(MOD - 2); }
  MI operator/(const MI m) const { return *this * m.inv(); }
  MI &operator/=(const MI m) { return (*this = *this / m); }
};

typedef MI<MOD> mi;

/* global variables */

mi inv2;

/* subroutines */

mi sigma(int n) {
  if (n <= 0) return 0;
  return mi(n) * (n + 1) * inv2;
}

mi calc(int n, int k) {
  mi sum = 0, inv = mi(n - k + 1).inv();
  for (int i = 0; i + k <= n; i++) {
    mi si =
      sigma(k) + sigma(k - 1)
      - sigma(k - 1 - i) - sigma(i - n + k * 2 - 1);
    sum += si * inv;
  }
  return sum * inv;
}

/* main */

int main() {
  inv2 = mi(2).inv();
  
  int h, w, a, b;
  scanf("%d%d%d%d", &h, &w, &a, &b);

  mi s = mi(a) * b * 2 - calc(h, a) * calc(w, b);
  printf("%d\n", (int)s);
  
  return 0;
}
0