結果

問題 No.2105 Avoid MeX
ユーザー pockynypockyny
提出日時 2022-10-21 23:10:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,451 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 70,780 KB
実行使用メモリ 44,424 KB
最終ジャッジ日時 2023-09-13 23:18:11
合計ジャッジ時間 2,274 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
13,612 KB
testcase_01 AC 14 ms
13,544 KB
testcase_02 AC 13 ms
13,552 KB
testcase_03 AC 13 ms
13,568 KB
testcase_04 AC 28 ms
34,036 KB
testcase_05 AC 14 ms
13,676 KB
testcase_06 AC 21 ms
25,656 KB
testcase_07 AC 25 ms
27,912 KB
testcase_08 AC 17 ms
17,684 KB
testcase_09 AC 31 ms
34,272 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 17 ms
21,272 KB
testcase_13 WA -
testcase_14 AC 23 ms
23,852 KB
testcase_15 AC 24 ms
27,852 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 13 ms
13,628 KB
testcase_19 AC 39 ms
44,316 KB
testcase_20 AC 38 ms
44,424 KB
testcase_21 AC 38 ms
44,232 KB
testcase_22 AC 39 ms
44,396 KB
testcase_23 AC 13 ms
13,564 KB
testcase_24 AC 14 ms
13,640 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 << inv[x + 1] << endl;
        return 0;
    }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++){
        //     cout << inv[x - j + 1] << " " << dp[las][j] << endl;
        // }
        for(j=0;j<=x;j++) (ans += inv[x - j + 1]*dp[las][j]%mod) %= mod;
        cout << (mod + 1 - ans)%mod << "\n";
    }
}
0