結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
13,580 KB
testcase_01 AC 13 ms
13,672 KB
testcase_02 AC 13 ms
13,560 KB
testcase_03 AC 13 ms
13,728 KB
testcase_04 AC 30 ms
33,984 KB
testcase_05 AC 12 ms
13,580 KB
testcase_06 AC 21 ms
25,520 KB
testcase_07 AC 24 ms
28,088 KB
testcase_08 AC 16 ms
17,608 KB
testcase_09 AC 31 ms
34,032 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 17 ms
21,260 KB
testcase_13 WA -
testcase_14 AC 22 ms
23,824 KB
testcase_15 AC 24 ms
27,912 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 13 ms
13,592 KB
testcase_19 AC 40 ms
44,264 KB
testcase_20 AC 40 ms
44,252 KB
testcase_21 AC 40 ms
44,300 KB
testcase_22 AC 40 ms
44,324 KB
testcase_23 AC 13 ms
13,564 KB
testcase_24 AC 13 ms
13,624 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){
        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;
            }
            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