結果

問題 No.1832 NAND Reversible
ユーザー ぷらぷら
提出日時 2022-02-04 21:54:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 998 bytes
コンパイル時間 3,189 ms
コンパイル使用メモリ 199,852 KB
実行使用メモリ 8,328 KB
最終ジャッジ日時 2023-09-02 04:47:47
合計ジャッジ時間 3,408 ms
ジャッジサーバーID
(参考情報)
judge13 / judge16
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 6 ms
8,116 KB
testcase_03 AC 7 ms
8,116 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 7 ms
8,048 KB
testcase_07 AC 7 ms
8,224 KB
testcase_08 AC 7 ms
8,044 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 7 ms
8,048 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 6 ms
8,096 KB
testcase_14 AC 6 ms
8,048 KB
testcase_15 AC 6 ms
8,044 KB
testcase_16 AC 6 ms
8,052 KB
testcase_17 AC 7 ms
8,116 KB
testcase_18 AC 6 ms
8,076 KB
testcase_19 AC 6 ms
8,144 KB
testcase_20 AC 6 ms
8,168 KB
testcase_21 AC 7 ms
8,328 KB
testcase_22 AC 7 ms
8,052 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 6 ms
8,040 KB
testcase_25 AC 6 ms
8,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr int mod = 998244353;

long long fac[200005], finv[200005], inv[200005];

void COMinit() {
    fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
    for (int i = 2; i < 200005; i++) {
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main() {
    int N,K;
    cin >> N >> K;
    if(K == 0) {
        cout << 1 << endl;
    }
    else if(K == 1) {
        if(N%2 == 0) {
            cout << 2 << endl;
        }
        else {
            cout << N-2 << endl;
        }
    }
    else {
        COMinit();
        long long ans = 0;
        for(int i = 0; i <= N-K; i += 2) {
            ans += COM(N-i-2,K-2)*(i+1)%mod;
            ans %= mod;
        }
        cout << ans << endl;
    }
}
0