結果

問題 No.2083 OR Subset
ユーザー pockynypockyny
提出日時 2022-09-25 23:10:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,878 ms / 3,000 ms
コード長 1,277 bytes
コンパイル時間 553 ms
コンパイル使用メモリ 70,228 KB
実行使用メモリ 209,112 KB
最終ジャッジ日時 2023-08-24 02:32:17
合計ジャッジ時間 18,713 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
14,240 KB
testcase_01 AC 12 ms
14,252 KB
testcase_02 AC 13 ms
14,752 KB
testcase_03 AC 988 ms
132,372 KB
testcase_04 AC 535 ms
81,992 KB
testcase_05 AC 1,702 ms
200,332 KB
testcase_06 AC 468 ms
74,512 KB
testcase_07 AC 49 ms
21,748 KB
testcase_08 AC 75 ms
25,444 KB
testcase_09 AC 977 ms
131,684 KB
testcase_10 AC 623 ms
91,832 KB
testcase_11 AC 356 ms
61,176 KB
testcase_12 AC 221 ms
44,740 KB
testcase_13 AC 1,856 ms
209,112 KB
testcase_14 AC 1,811 ms
206,100 KB
testcase_15 AC 1,823 ms
207,220 KB
testcase_16 AC 1,864 ms
208,888 KB
testcase_17 AC 1,859 ms
208,988 KB
testcase_18 AC 13 ms
14,276 KB
testcase_19 AC 1,878 ms
208,892 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){
    a %= mod;
    ll ret = 1;
    while(x){
        if(x&1) (ret *= a) %= mod;
        (a *= a) %= mod; x /= 2;
    }
    return ret;
}

ll dp[5010][5010];
int main(){
    int i,j,n; cin >> n;
    solve();
    dp[0][0] = 1;
    for(i=0;i<=n;i++){
        for(j=0;j<=n;j++){
            if(i && j) dp[i][j] += dp[i - 1][j - 1];
            if(i) dp[i][j] += dp[i - 1][j]*j;
            dp[i][j] %= mod;
        }
    }
    ll ans = 1;
    for(i=1;i<=n;i++){
        for(j=1;j<=i;j++){
            ll val = dp[i][j]*nck(n,i)%mod;
            //ll val = nck(n,i)*nck(i - 1,i - j)%mod*nck(i,j)%mod;
            (val *= pw(pw(2,j) - j + mod,n - i)) %= mod;
            (ans += val) %= mod;
            //cout << i << " " << j << " " << val << "\n";
        }
    }
    cout << ans << "\n";
}
0