結果

問題 No.2105 Avoid MeX
ユーザー pockynypockyny
提出日時 2022-10-21 23:14:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,333 bytes
コンパイル時間 763 ms
コンパイル使用メモリ 69,840 KB
実行使用メモリ 44,332 KB
最終ジャッジ日時 2023-09-13 23:23:41
合計ジャッジ時間 2,196 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
13,696 KB
testcase_01 AC 13 ms
13,540 KB
testcase_02 AC 13 ms
13,584 KB
testcase_03 AC 13 ms
13,800 KB
testcase_04 AC 30 ms
33,988 KB
testcase_05 AC 13 ms
13,584 KB
testcase_06 AC 20 ms
25,652 KB
testcase_07 AC 24 ms
27,824 KB
testcase_08 AC 17 ms
17,576 KB
testcase_09 AC 30 ms
34,000 KB
testcase_10 AC 13 ms
13,572 KB
testcase_11 AC 12 ms
13,508 KB
testcase_12 AC 17 ms
21,096 KB
testcase_13 AC 12 ms
13,528 KB
testcase_14 AC 22 ms
23,820 KB
testcase_15 AC 24 ms
27,816 KB
testcase_16 AC 13 ms
13,528 KB
testcase_17 AC 13 ms
13,564 KB
testcase_18 AC 13 ms
13,564 KB
testcase_19 AC 38 ms
44,256 KB
testcase_20 AC 38 ms
44,280 KB
testcase_21 AC 37 ms
44,280 KB
testcase_22 AC 39 ms
44,332 KB
testcase_23 AC 13 ms
13,568 KB
testcase_24 AC 13 ms
13,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;
using ll = long long;
const int MX = 400010;
ll f[MX],inv[MX],fi[MX];
constexpr ll mod = 998244353;
void solve(){
    inv[1] = 1;
    for(int i=2;i<MX;i++){
        inv[i] = mod - (mod/i)*inv[mod%i]%mod;
    }
    f[0] = fi[0] = 1;
    for(int i=1;i<MX;i++){
        f[i] = f[i-1]*i%mod;
        fi[i] = fi[i-1]*inv[i]%mod;
    }
}

ll nck(ll n, ll k){
    if(n<0 || k<0 || n<k) return 0;
    return f[n]*fi[k]%mod*fi[n-k]%mod;
}

ll pw(ll a,ll x){
    ll ret = 1;
    while(x){
        if(x&1) (ret *= a) %= mod;
        (a *= a) %= mod; x /= 2;
    }
    return ret;
}

ll dp[2010][2010] = {};
int main(){
    ll i,j,c,x; cin >> c >> x;
    solve();
    if(x==0){
        cout << inv[c + 1] << endl;
    }else if(c>=x){
        cout << (mod + 1 - inv[x + 1])%mod << endl;
    }else{
        dp[0][0] = 1;
        int las = 0;
        for(i=1;i<=2000;i++){
            if(c + i>x) break;
            for(j=0;j<=x;j++){
                dp[i][j] = inv[c + i]*j%mod*dp[i - 1][j]%mod;
                if(j && (c + i  + 1 - j)>=0) (dp[i][j] += inv[c + i]*(c + i + 1 - j)%mod*dp[i - 1][j - 1]%mod) %= mod;
            }
            las = i;
        }
        ll ans = 0;
        for(j=0;j<=x;j++) (ans += inv[x - j + 1]*dp[las][j]%mod) %= mod;
        cout << (mod + 1 - ans)%mod << "\n";
    }
}
0