結果

問題 No.2383 Naphthol
ユーザー Yaowei LyuYaowei Lyu
提出日時 2023-07-14 21:52:42
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,200 bytes
コンパイル時間 2,714 ms
コンパイル使用メモリ 246,188 KB
実行使用メモリ 6,392 KB
最終ジャッジ日時 2023-10-14 11:59:28
合計ジャッジ時間 3,870 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 6 ms
4,348 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 1 ms
4,352 KB
testcase_09 WA -
testcase_10 AC 35 ms
6,104 KB
testcase_11 AC 35 ms
6,192 KB
testcase_12 AC 29 ms
5,332 KB
testcase_13 AC 29 ms
5,640 KB
testcase_14 AC 25 ms
5,072 KB
testcase_15 WA -
testcase_16 AC 29 ms
5,568 KB
testcase_17 WA -
testcase_18 AC 29 ms
5,660 KB
testcase_19 AC 27 ms
5,332 KB
testcase_20 AC 36 ms
6,164 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) {
        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 * power(4, mod - 2) % mod;
}
0