結果

問題 No.2383 Naphthol
ユーザー Yaowei LyuYaowei Lyu
提出日時 2023-07-14 21:53:32
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,210 bytes
コンパイル時間 2,533 ms
コンパイル使用メモリ 245,956 KB
実行使用メモリ 6,260 KB
最終ジャッジ日時 2023-10-14 12:00:43
合計ジャッジ時間 3,682 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 6 ms
4,352 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 36 ms
6,260 KB
testcase_10 AC 36 ms
6,212 KB
testcase_11 AC 35 ms
6,128 KB
testcase_12 AC 28 ms
5,492 KB
testcase_13 AC 29 ms
5,632 KB
testcase_14 AC 24 ms
5,100 KB
testcase_15 AC 19 ms
4,600 KB
testcase_16 AC 29 ms
5,684 KB
testcase_17 AC 3 ms
4,352 KB
testcase_18 AC 29 ms
5,668 KB
testcase_19 AC 27 ms
5,436 KB
testcase_20 AC 36 ms
6,212 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;
    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