結果
問題 | No.2383 Naphthol |
ユーザー |
|
提出日時 | 2023-07-14 21:59:53 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 33 ms / 2,000 ms |
コード長 | 1,327 bytes |
コンパイル時間 | 2,891 ms |
コンパイル使用メモリ | 247,680 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-16 06:59:12 |
合計ジャッジ時間 | 3,571 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
#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;}