結果

問題 No.1310 量子アニーリング
ユーザー face4face4
提出日時 2020-12-07 22:38:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,262 bytes
コンパイル時間 609 ms
コンパイル使用メモリ 70,796 KB
実行使用メモリ 6,504 KB
最終ジャッジ日時 2023-10-17 16:41:26
合計ジャッジ時間 1,931 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,348 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 17 ms
4,348 KB
testcase_14 AC 25 ms
4,656 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 46 ms
5,712 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 12 ms
4,348 KB
testcase_21 AC 8 ms
4,348 KB
testcase_22 AC 64 ms
6,504 KB
testcase_23 AC 18 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;

typedef long long ll;
const ll mod = 998244353;

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

struct ModComb{
    vector<ll> po, inv;
    ll N;

    ModComb(ll n) : N(n), po(n), inv(n) {
        po[0] = 1;
        for(int i = 1; i < N; i++)  po[i] = (po[i-1] * i) % mod;
        inv[N-1] = modpow(po[N-1], mod-2, mod);
        for(int i = N-2; i >= 0; i--)   inv[i] = (inv[i+1] * (i+1)) % mod;
    }
    
    ll nCk(ll n, ll k){
        if(k == 0)  return 1;
        if(n < k)   return 0;
        return (((po[n]*inv[n-k])%mod)*inv[k])%mod;
    }

    ll nPk(ll n, ll k){
        if(k == 0)  return 1;
        if(n < k)   return 0;
        return (po[n]*inv[n-k])%mod;
    }

    ll nHk(ll n, ll k){
        if(n == 0 && k == 0)    return 1;
        return nCk(n+k-1, k-1);
    }
};

int main(){
    int n;
    cin >> n;
    ll ans = modpow(2,n,mod)*2%mod;
    ModComb mc(n+1);
    for(int i = 2; i < n; i += 2){
        ans += mc.nCk(n, i)*modpow(2,abs(n-2*i),mod)*2%mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}
0