結果

問題 No.1960 Guruguru Permutation
ユーザー SenioriousSeniorious
提出日時 2022-10-15 19:36:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 715 bytes
コンパイル時間 2,071 ms
コンパイル使用メモリ 197,680 KB
実行使用メモリ 4,404 KB
最終ジャッジ日時 2023-09-09 03:03:45
合計ジャッジ時間 3,514 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define File(a) freopen(a ".in", "r", stdin), freopen(a ".out", "w", stdout)

const int N = 200005;
const int Mod = 998244353;

int iv[N];

int main() {
  int n, a, b;
  scanf("%d %d %d", &n, &a, &b);
  if (a + b > n) {
    int now = a + b - n;
    n -= now, a -= now, b -= now;
  }
  iv[1] = 1;
  for (int i = 2; i <= n; ++i) iv[i] = 1ll * (Mod - Mod / i) * iv[Mod % i] % Mod;
  int ans = 0;
  for (int i = 0, Ca = 1, Cb = 1; i <= std::min(a, b); ++i) {
    ans = (ans + 1ll * Ca * Cb) % Mod;
    Ca = 1ll * Ca * (a - i) % Mod * iv[i + 1] % Mod;
    Cb = 1ll * Cb * (b - i) % Mod;
  }
  for (int i = a + b + 1; i <= n; ++i) ans = 1ll * ans * i % Mod;
  printf("%d\n", ans);
  return 0;
}
0