結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 13 ms
13,616 KB
testcase_02 WA -
testcase_03 AC 13 ms
13,572 KB
testcase_04 AC 29 ms
34,004 KB
testcase_05 AC 13 ms
13,724 KB
testcase_06 AC 20 ms
25,516 KB
testcase_07 AC 25 ms
27,848 KB
testcase_08 AC 17 ms
17,772 KB
testcase_09 AC 31 ms
34,024 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 17 ms
21,220 KB
testcase_13 WA -
testcase_14 AC 22 ms
23,768 KB
testcase_15 AC 25 ms
27,852 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 13 ms
13,820 KB
testcase_19 AC 39 ms
44,316 KB
testcase_20 AC 39 ms
44,264 KB
testcase_21 AC 39 ms
44,328 KB
testcase_22 AC 39 ms
44,236 KB
testcase_23 AC 13 ms
13,560 KB
testcase_24 AC 13 ms
13,548 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(){
    int i,j,c,x; cin >> c >> x;
    solve();
    if(x==0){
        if(c>0) cout << inv[c + 1] << endl;
        else cout << 0 << endl;
    }
    else if(c>=x){
        cout << inv[x] << 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;
            }
            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