結果

問題 No.1832 NAND Reversible
ユーザー otoshigootoshigo
提出日時 2022-02-05 15:18:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 1,771 bytes
コンパイル時間 2,276 ms
コンパイル使用メモリ 203,232 KB
実行使用メモリ 8,852 KB
最終ジャッジ日時 2023-09-02 06:44:11
合計ジャッジ時間 4,293 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
5,248 KB
testcase_01 AC 31 ms
5,432 KB
testcase_02 AC 31 ms
5,316 KB
testcase_03 AC 36 ms
8,304 KB
testcase_04 AC 35 ms
8,852 KB
testcase_05 AC 34 ms
8,544 KB
testcase_06 AC 32 ms
5,320 KB
testcase_07 AC 35 ms
8,004 KB
testcase_08 AC 36 ms
8,708 KB
testcase_09 AC 34 ms
8,704 KB
testcase_10 AC 31 ms
5,196 KB
testcase_11 AC 32 ms
5,304 KB
testcase_12 AC 32 ms
5,440 KB
testcase_13 AC 32 ms
5,424 KB
testcase_14 AC 31 ms
5,180 KB
testcase_15 AC 32 ms
5,932 KB
testcase_16 AC 33 ms
6,540 KB
testcase_17 AC 34 ms
8,060 KB
testcase_18 AC 31 ms
5,420 KB
testcase_19 AC 31 ms
5,744 KB
testcase_20 AC 31 ms
5,240 KB
testcase_21 AC 36 ms
8,672 KB
testcase_22 AC 36 ms
8,652 KB
testcase_23 AC 32 ms
5,300 KB
testcase_24 AC 31 ms
5,356 KB
testcase_25 AC 33 ms
7,060 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];
}

vector<mint> B(200010);

mint b(int x, int y){
    if (y == 0){
        if (x >= 2) B[y] = 1;
        else B[y] = 0;
    }
    else if (y == 1){
        B[y] = x-1;
    }
    else B[y] = cmb_mint(x+y-2,y) + b(x,y-2);
    return B[y];
}

mint a(int x, int y){
    if (x == 0 || y == 0) return 1;
    if (y == 1){
        if (x == 1) return 2;
        else return x-1;
    }
    if (x == 1){
        if (y%2 == 0) return y-1;
        else 2;
    }
    return a(x,y-2) + cmb_mint(x+y-2,x-2) + 2*B[y-2];
}

int main(){
    set_fac();
    int n,k; cin >> n >> k;
    b(k,n-k);
    cout << a(k,n-k).val() << endl;
}
0