結果

問題 No.1832 NAND Reversible
ユーザー pockynypockyny
提出日時 2022-02-04 23:02:25
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,107 bytes
コンパイル時間 794 ms
コンパイル使用メモリ 70,144 KB
実行使用メモリ 8,364 KB
最終ジャッジ日時 2023-09-02 05:42:49
合計ジャッジ時間 2,162 ms
ジャッジサーバーID
(参考情報)
judge13 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
8,096 KB
testcase_01 AC 8 ms
8,112 KB
testcase_02 AC 8 ms
8,328 KB
testcase_03 AC 9 ms
8,172 KB
testcase_04 AC 8 ms
8,052 KB
testcase_05 AC 7 ms
8,048 KB
testcase_06 AC 9 ms
8,036 KB
testcase_07 AC 8 ms
8,052 KB
testcase_08 AC 8 ms
8,044 KB
testcase_09 AC 8 ms
8,112 KB
testcase_10 AC 8 ms
8,100 KB
testcase_11 AC 8 ms
8,044 KB
testcase_12 AC 7 ms
8,056 KB
testcase_13 AC 8 ms
8,116 KB
testcase_14 AC 7 ms
8,104 KB
testcase_15 AC 8 ms
8,052 KB
testcase_16 AC 8 ms
8,364 KB
testcase_17 AC 8 ms
8,044 KB
testcase_18 AC 8 ms
8,172 KB
testcase_19 AC 8 ms
8,108 KB
testcase_20 AC 8 ms
8,104 KB
testcase_21 AC 8 ms
8,176 KB
testcase_22 AC 9 ms
8,248 KB
testcase_23 AC 8 ms
8,112 KB
testcase_24 AC 8 ms
8,048 KB
testcase_25 AC 8 ms
8,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;
using ll = long long;
const int MX = 200010;
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;
}

int main(){
    int i,n,k; cin >> n >> k;
    solve();
    if(k==0){
        cout << 1 << endl;
        return 0;
    }
    if(k==1){
        if(n&1) cout << n - 2 << endl;
        else cout << 2 << endl;
        return 0;
    }
    ll ans = 0;
    if(n&1){
        for(i=1;i<n;i+=2){
            (ans += max(n - i - 1,0)*nck(i,k - 2)) %= mod;
        }
    }else{
        for(i=0;i<n;i+=2){
            (ans += max(n - i - 1,0)*nck(i,k - 2)) %= mod;
        }
    }
    cout << ans << endl;
}
0