結果

問題 No.1832 NAND Reversible
ユーザー otoshigootoshigo
提出日時 2022-02-05 14:48:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,680 bytes
コンパイル時間 4,391 ms
コンパイル使用メモリ 203,820 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2023-09-02 06:41:47
合計ジャッジ時間 4,339 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
5,424 KB
testcase_01 AC 32 ms
5,296 KB
testcase_02 AC 32 ms
5,360 KB
testcase_03 AC 35 ms
8,316 KB
testcase_04 AC 36 ms
8,704 KB
testcase_05 AC 35 ms
8,652 KB
testcase_06 AC 32 ms
5,372 KB
testcase_07 AC 34 ms
8,016 KB
testcase_08 AC 35 ms
8,644 KB
testcase_09 WA -
testcase_10 AC 31 ms
5,284 KB
testcase_11 AC 31 ms
5,252 KB
testcase_12 AC 31 ms
5,424 KB
testcase_13 AC 30 ms
5,428 KB
testcase_14 AC 31 ms
5,356 KB
testcase_15 AC 33 ms
5,876 KB
testcase_16 AC 34 ms
6,540 KB
testcase_17 AC 35 ms
7,992 KB
testcase_18 AC 32 ms
5,356 KB
testcase_19 AC 32 ms
5,620 KB
testcase_20 AC 32 ms
5,360 KB
testcase_21 AC 35 ms
8,532 KB
testcase_22 AC 35 ms
8,700 KB
testcase_23 AC 32 ms
5,324 KB
testcase_24 AC 32 ms
5,320 KB
testcase_25 AC 33 ms
7,120 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) B[y] = 0;
    else if (y == 0){
        if (x >= 2) B[y] = 1;
        else B[y] = 0;
    }
    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;
    }
    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