結果

問題 No.2105 Avoid MeX
ユーザー baLoon8128baLoon8128
提出日時 2022-10-21 23:28:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 984 bytes
コンパイル時間 3,920 ms
コンパイル使用メモリ 231,564 KB
実行使用メモリ 19,160 KB
最終ジャッジ日時 2023-09-13 23:36:06
合計ジャッジ時間 5,653 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 30 ms
13,116 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 15 ms
8,624 KB
testcase_07 AC 27 ms
16,568 KB
testcase_08 AC 13 ms
11,512 KB
testcase_09 AC 36 ms
17,912 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 8 ms
6,556 KB
testcase_13 AC 2 ms
4,600 KB
testcase_14 AC 22 ms
14,964 KB
testcase_15 AC 23 ms
13,192 KB
testcase_16 AC 15 ms
18,924 KB
testcase_17 AC 15 ms
19,160 KB
testcase_18 AC 15 ms
19,160 KB
testcase_19 AC 52 ms
19,040 KB
testcase_20 AC 51 ms
18,612 KB
testcase_21 AC 51 ms
18,704 KB
testcase_22 AC 51 ms
18,660 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repr(i, n) for (int i = (int)(n - 1); i >= 0; --i)

using mint = modint998244353;
int main() {
    int c, x;
    cin >> c >> x;
    if (x == 0) {
        cout << mint(c + 1).inv().val() << endl;
    } else {
        c = min(c, x);
        vector<vector<mint>> dp(x + 1, vector<mint>(x + 1, 0));
        dp[c][0] = 1;
        for (int k = c + 1; k <= x; k++) {
            mint kinv = mint(k).inv();
            repr(i, x) {
                dp[k][i] += dp[k - 1][i] * i * kinv;
                dp[k][i + 1] += dp[k - 1][i] * (k - i) * kinv;
            }
        }
        mint ret = 1;
        rep(i, x + 1) ret -= dp[x][i] / (x + 1 - i);
        cout << ret.val() << endl;
    }
    return 0;
}
0