結果

問題 No.1832 NAND Reversible
ユーザー otoshigootoshigo
提出日時 2022-02-05 16:02:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,541 bytes
コンパイル時間 2,097 ms
コンパイル使用メモリ 202,292 KB
実行使用メモリ 4,688 KB
最終ジャッジ日時 2023-09-02 06:45:41
合計ジャッジ時間 4,011 ms
ジャッジサーバーID
(参考情報)
judge14 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
4,648 KB
testcase_01 AC 32 ms
4,408 KB
testcase_02 AC 31 ms
4,580 KB
testcase_03 AC 32 ms
4,648 KB
testcase_04 AC 31 ms
4,648 KB
testcase_05 AC 31 ms
4,464 KB
testcase_06 AC 31 ms
4,396 KB
testcase_07 AC 32 ms
4,636 KB
testcase_08 AC 32 ms
4,572 KB
testcase_09 AC 31 ms
4,408 KB
testcase_10 AC 32 ms
4,688 KB
testcase_11 AC 31 ms
4,628 KB
testcase_12 AC 31 ms
4,404 KB
testcase_13 AC 32 ms
4,628 KB
testcase_14 AC 31 ms
4,404 KB
testcase_15 AC 31 ms
4,516 KB
testcase_16 AC 32 ms
4,408 KB
testcase_17 AC 31 ms
4,508 KB
testcase_18 AC 31 ms
4,636 KB
testcase_19 AC 31 ms
4,588 KB
testcase_20 AC 32 ms
4,408 KB
testcase_21 AC 32 ms
4,416 KB
testcase_22 AC 32 ms
4,652 KB
testcase_23 AC 31 ms
4,680 KB
testcase_24 AC 31 ms
4,584 KB
testcase_25 AC 32 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using namespace atcoder;
using ll = long long;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,a,b) for (int i = a; i < b; i++)
#define rrep2(i,a,b) for (int i = a-1; i >= b; i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}
template<class T> T pow(T x, T y){if (y == 0) return 1.0;T p = pow(x,y/2);if (y%2 == 0) return p*p;else return p*p*x;}

const int MAX = 200010;

vector<mint> fac(MAX),finv(MAX);

void set_fac(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i-1]*i;
        finv[i] = finv[i-1] * mint(i).inv();
    }
}

mint cmb_mint(int n, int r){
    if (r < 0 || n < r) return 0;
    return fac[n]*finv[n-r]*finv[r];
}

int main(){
    set_fac();
    int n,k; cin >> n >> k;
    if (k == 0){
        cout << 1 << endl;
    }
    else if (k == 1){
        if((n-k)%2 == 0) cout << n-2 << endl;
        else cout << 2 << endl;
    }
    else{
        mint ans = 0;
        rep(i,n-1){
            if ((n-i)%2 == 0) ans += cmb_mint(i,k-2) * (n-i-1);
        }
        cout << ans.val() << endl;
    }
}
0