結果
問題 | No.1771 A DELETEQ |
ユーザー | hitonanode |
提出日時 | 2021-11-23 12:53:29 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 27 ms / 3,500 ms |
コード長 | 2,573 bytes |
コンパイル時間 | 2,393 ms |
コンパイル使用メモリ | 120,716 KB |
実行使用メモリ | 11,440 KB |
最終ジャッジ日時 | 2024-07-03 21:10:06 |
合計ジャッジ時間 | 10,784 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 14 ms
11,080 KB |
testcase_01 | AC | 15 ms
11,124 KB |
testcase_02 | AC | 27 ms
11,156 KB |
testcase_03 | AC | 15 ms
11,192 KB |
testcase_04 | AC | 27 ms
11,440 KB |
testcase_05 | AC | 26 ms
11,376 KB |
testcase_06 | AC | 15 ms
11,092 KB |
testcase_07 | AC | 17 ms
11,316 KB |
testcase_08 | AC | 14 ms
11,112 KB |
testcase_09 | AC | 16 ms
11,256 KB |
testcase_10 | AC | 22 ms
11,184 KB |
testcase_11 | AC | 17 ms
11,136 KB |
testcase_12 | AC | 19 ms
11,156 KB |
testcase_13 | AC | 22 ms
11,372 KB |
testcase_14 | AC | 20 ms
11,160 KB |
testcase_15 | AC | 24 ms
11,204 KB |
testcase_16 | AC | 24 ms
11,284 KB |
testcase_17 | AC | 20 ms
11,308 KB |
testcase_18 | AC | 17 ms
11,164 KB |
testcase_19 | AC | 15 ms
11,144 KB |
testcase_20 | AC | 25 ms
11,356 KB |
testcase_21 | AC | 19 ms
11,128 KB |
testcase_22 | AC | 18 ms
11,096 KB |
testcase_23 | AC | 23 ms
11,200 KB |
testcase_24 | AC | 17 ms
11,180 KB |
testcase_25 | AC | 15 ms
11,012 KB |
testcase_26 | AC | 19 ms
11,100 KB |
testcase_27 | AC | 16 ms
11,148 KB |
testcase_28 | AC | 15 ms
11,216 KB |
evil_hand_1.txt | AC | 1,020 ms
18,700 KB |
evil_hand_2.txt | AC | 15 ms
11,124 KB |
evil_hand_3.txt | AC | 77 ms
18,700 KB |
evil_random_1.txt | AC | 232 ms
12,508 KB |
evil_random_2.txt | AC | 366 ms
14,104 KB |
evil_random_3.txt | AC | 455 ms
13,868 KB |
evil_random_4.txt | AC | 920 ms
16,612 KB |
evil_random_5.txt | AC | 513 ms
14,708 KB |
evil_random_6.txt | AC | 217 ms
12,608 KB |
evil_random_7.txt | AC | 1,035 ms
18,240 KB |
evil_random_8.txt | AC | 856 ms
18,256 KB |
evil_random_9.txt | AC | 939 ms
17,384 KB |
ソースコード
#include <cassert> #include <iostream> #include <vector> using namespace std; #include <atcoder/modint> #include <atcoder/convolution> using mint = atcoder::modint998244353; template <typename modint> struct acl_fac { std::vector<modint> facs, facinvs; acl_fac(int N) { assert(-1 <= N and N < modint::mod()); facs.resize(N + 1, 1); for (int i = 1; i <= N; i++) facs[i] = facs[i - 1] * i; facinvs.assign(N + 1, facs.back().inv()); for (int i = N; i > 0; i--) facinvs[i - 1] = facinvs[i] * i; } modint ncr(int n, int r) const { if (n < 0 or r < 0 or n < r) return 0; return facs[n] * facinvs[r] * facinvs[n - r]; } modint operator[](int i) const { return facs[i]; } modint finv(int i) const { return facinvs[i]; } }; acl_fac<mint> fac(1000000); // https://hitonanode.github.io/cplib-cpp/formal_power_series/coeff_of_rational_function.hpp // Calculate [x^N](num(x) / den(x)) // - Coplexity: O(LlgLlgN) ( L = size(num) + size(den) ) // - Reference: `Bostan–Mori algorithm` <https://qiita.com/ryuhe1/items/da5acbcce4ac1911f47a> template <typename Tp> Tp coefficient_of_rational_function(long long N, std::vector<Tp> num, std::vector<Tp> den) { assert(N >= 0); while (den.size() and den.back() == 0) den.pop_back(); assert(den.size()); int h = 0; while (den[h] == 0) h++; N += h; den.erase(den.begin(), den.begin() + h); if (den.size() == 1) return N < int(num.size()) ? num[N] / den[0] : 0; while (N) { std::vector<Tp> g = den; for (size_t i = 1; i < g.size(); i += 2) { g[i] = -g[i]; } auto conv_num_g = atcoder::convolution(num, g); num.resize((conv_num_g.size() + 1 - (N & 1)) / 2); for (size_t i = 0; i < num.size(); i++) { num[i] = conv_num_g[i * 2 + (N & 1)]; } auto conv_den_g = atcoder::convolution(den, g); for (size_t i = 0; i < den.size(); i++) { den[i] = conv_den_g[i * 2]; } N >>= 1; } return num[0] / den[0]; } int main() { // [x^M] ((1 + 2x)^(N + 1) - (x - x^2)^(N + 1)) / ((1 - x)^(N + 1) (1 + x + x^2)) int N, M; cin >> N >> M; vector<mint> num(N * 2 + 3), den(N + 4); for (int d = 0; d <= N + 1; ++d) { mint ncr = fac.ncr(N + 1, d); mint sgn = d % 2 ? -1 : 1; num[d] += mint(2).pow(d) * ncr; num[d * 2 + (N + 1 - d)] -= sgn * ncr; den[d] += ncr * sgn; den[d + 1] += ncr * sgn; den[d + 2] += ncr * sgn; } cout << coefficient_of_rational_function(M, num, den).val() << '\n'; }