結果

問題 No.2105 Avoid MeX
ユーザー milanis48663220milanis48663220
提出日時 2022-10-21 23:14:23
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 306 ms / 2,000 ms
コード長 2,183 bytes
コンパイル時間 1,181 ms
コンパイル使用メモリ 118,476 KB
実行使用メモリ 38,716 KB
最終ジャッジ日時 2023-09-13 23:22:46
合計ジャッジ時間 4,149 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
38,508 KB
testcase_01 AC 11 ms
38,528 KB
testcase_02 AC 11 ms
38,648 KB
testcase_03 AC 11 ms
38,688 KB
testcase_04 AC 132 ms
38,576 KB
testcase_05 AC 11 ms
38,464 KB
testcase_06 AC 48 ms
38,516 KB
testcase_07 AC 58 ms
38,456 KB
testcase_08 AC 17 ms
38,508 KB
testcase_09 AC 125 ms
38,452 KB
testcase_10 AC 11 ms
38,452 KB
testcase_11 AC 12 ms
38,640 KB
testcase_12 AC 24 ms
38,544 KB
testcase_13 AC 12 ms
38,544 KB
testcase_14 AC 42 ms
38,712 KB
testcase_15 AC 70 ms
38,640 KB
testcase_16 AC 12 ms
38,660 KB
testcase_17 AC 12 ms
38,716 KB
testcase_18 AC 12 ms
38,512 KB
testcase_19 AC 306 ms
38,484 KB
testcase_20 AC 303 ms
38,512 KB
testcase_21 AC 306 ms
38,452 KB
testcase_22 AC 304 ms
38,524 KB
testcase_23 AC 12 ms
38,592 KB
testcase_24 AC 12 ms
38,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/modint>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

using mint = atcoder::modint998244353;

ostream& operator<<(ostream& os, const mint& m){
    os << m.val();
    return os;
}

mint dp[3000][3000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int c, x; cin >> c >> x;
    if(x == 0){
        cout << mint(1)/(c+1) << endl;
        return 0;
    }
    dp[0][0] = 1;
    int mx = 0;
    for(int i = 1; c+i-1 < x; i++){
        chmax(mx, i);
        for(int k = 0; k < i; k++){
            if(dp[i-1][k].val() == 0) continue;
            int candidate = c+i-k;
            mint p = mint(candidate)/mint(c+i);
            // cout << i << ' ' << k << ' ' << p << endl;
            dp[i][k+1] += dp[i-1][k]*p;
            dp[i][k] += dp[i-1][k]*(1-p);
        }
    }
    mint ans = 0;
    for(int used = 0; used <= x; used++){
        int k = x+1-used;
        ans += dp[mx][used]*(k-1)/k;
        // cout << k << ' ' << dp[mx][used] << endl;
    }
    cout << ans << endl;
}
0