結果

問題 No.1832 NAND Reversible
ユーザー ぷらぷら
提出日時 2022-02-04 21:51:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 905 bytes
コンパイル時間 2,151 ms
コンパイル使用メモリ 199,048 KB
実行使用メモリ 8,280 KB
最終ジャッジ日時 2023-09-02 04:45:34
合計ジャッジ時間 3,289 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 WA -
testcase_02 AC 6 ms
8,044 KB
testcase_03 AC 7 ms
8,044 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 6 ms
8,016 KB
testcase_07 AC 7 ms
8,276 KB
testcase_08 AC 6 ms
8,072 KB
testcase_09 WA -
testcase_10 AC 6 ms
8,032 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 6 ms
8,020 KB
testcase_14 AC 6 ms
8,088 KB
testcase_15 AC 6 ms
8,112 KB
testcase_16 AC 7 ms
8,060 KB
testcase_17 AC 7 ms
8,064 KB
testcase_18 AC 6 ms
8,048 KB
testcase_19 AC 6 ms
8,032 KB
testcase_20 AC 6 ms
8,124 KB
testcase_21 AC 7 ms
8,044 KB
testcase_22 AC 7 ms
8,280 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 6 ms
8,112 KB
testcase_25 AC 7 ms
8,028 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) {
        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