結果

問題 No.2383 Naphthol
ユーザー Yaowei LyuYaowei Lyu
提出日時 2023-07-14 21:59:53
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 1,327 bytes
コンパイル時間 2,552 ms
コンパイル使用メモリ 246,816 KB
実行使用メモリ 6,180 KB
最終ジャッジ日時 2023-10-14 12:09:18
合計ジャッジ時間 3,803 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,356 KB
testcase_02 AC 5 ms
4,352 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 36 ms
6,116 KB
testcase_10 AC 36 ms
6,116 KB
testcase_11 AC 35 ms
6,156 KB
testcase_12 AC 28 ms
5,388 KB
testcase_13 AC 29 ms
5,600 KB
testcase_14 AC 25 ms
5,060 KB
testcase_15 AC 19 ms
4,764 KB
testcase_16 AC 30 ms
5,636 KB
testcase_17 AC 3 ms
4,352 KB
testcase_18 AC 29 ms
5,628 KB
testcase_19 AC 27 ms
5,328 KB
testcase_20 AC 36 ms
6,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
constexpr i64 mod = 998244353;
i64 power(i64 a, i64 r) {
    i64 res = 1;
    for (; r; r >>= 1, a = a * a % mod) {
        if (r & 1) {
            res = res * a % mod;
        }
    }
    return res;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    i64 n, k;
    cin >> n >> k;
    if (n == 1) {
        array<int, 7> ans = {1, 1, 3, 3, 3, 1, 1};
        cout << ans[k];
        return 0;
    }
    int m = 2 * n + 4;
    vector<i64> f(m + 1, 1), g(m + 1, 1);
    for (i64 i = 1; i <= m; i += 1) {
        g[i] = power(f[i] = f[i - 1] * i % mod, mod - 2);
    }
    auto c = [&](int n, int m) {
        if (n < m or m < 0) {
            return i64(0);
        }
        return f[n] * g[m] % mod * g[n - m] % mod;
    };
    i64 ans = c(m, k);
    if (k % 2 == 0) {
        ans += c(m / 2, k / 2);
    }
    if (n % 2 == 0) {
        if (k % 2 == 0) {
            ans += c(m / 2, k / 2);
        }
    } else {
        for (int i = 0; i <= 2 and i <= k; i += 1) {
            if ((k - i) % 2 == 0) {
                ans += c(2, i) * c(m / 2 - 1, (k - i) / 2) % mod;
            }
        }
    }
    if (k % 2 == 0) {
        ans += c(m / 2, k / 2);
    }
    // cerr << ans << "\n";
    cout << ans % mod * power(4, mod - 2) % mod;
}
0