結果
問題 | No.2605 Pickup Parentheses |
ユーザー | risujiroh |
提出日時 | 2024-01-12 22:14:01 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 8,068 bytes |
コンパイル時間 | 4,384 ms |
コンパイル使用メモリ | 303,036 KB |
実行使用メモリ | 33,324 KB |
最終ジャッジ日時 | 2024-09-27 22:41:09 |
合計ジャッジ時間 | 9,223 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 13 ms
11,028 KB |
testcase_01 | AC | 14 ms
11,008 KB |
testcase_02 | AC | 14 ms
10,992 KB |
testcase_03 | AC | 15 ms
11,092 KB |
testcase_04 | AC | 14 ms
11,136 KB |
testcase_05 | AC | 15 ms
11,136 KB |
testcase_06 | AC | 16 ms
11,256 KB |
testcase_07 | AC | 15 ms
11,136 KB |
testcase_08 | AC | 15 ms
11,264 KB |
testcase_09 | AC | 14 ms
11,008 KB |
testcase_10 | AC | 15 ms
11,136 KB |
testcase_11 | AC | 14 ms
11,136 KB |
testcase_12 | AC | 14 ms
11,136 KB |
testcase_13 | AC | 13 ms
11,008 KB |
testcase_14 | AC | 14 ms
11,128 KB |
testcase_15 | AC | 14 ms
11,136 KB |
testcase_16 | AC | 14 ms
11,008 KB |
testcase_17 | AC | 14 ms
11,008 KB |
testcase_18 | AC | 72 ms
17,664 KB |
testcase_19 | AC | 43 ms
14,336 KB |
testcase_20 | AC | 19 ms
11,748 KB |
testcase_21 | AC | 18 ms
11,476 KB |
testcase_22 | AC | 15 ms
11,136 KB |
testcase_23 | AC | 74 ms
17,616 KB |
testcase_24 | AC | 19 ms
11,648 KB |
testcase_25 | AC | 89 ms
19,292 KB |
testcase_26 | AC | 92 ms
20,220 KB |
testcase_27 | AC | 65 ms
16,668 KB |
testcase_28 | AC | 17 ms
11,012 KB |
testcase_29 | AC | 20 ms
11,796 KB |
testcase_30 | AC | 30 ms
13,416 KB |
testcase_31 | AC | 15 ms
11,104 KB |
testcase_32 | AC | 14 ms
11,008 KB |
testcase_33 | AC | 53 ms
16,040 KB |
testcase_34 | AC | 15 ms
11,136 KB |
testcase_35 | AC | 14 ms
11,008 KB |
testcase_36 | AC | 16 ms
11,076 KB |
testcase_37 | AC | 46 ms
14,816 KB |
testcase_38 | AC | 25 ms
12,520 KB |
testcase_39 | AC | 18 ms
11,520 KB |
testcase_40 | AC | 46 ms
14,732 KB |
testcase_41 | AC | 42 ms
14,484 KB |
testcase_42 | AC | 58 ms
15,988 KB |
testcase_43 | AC | 21 ms
12,160 KB |
testcase_44 | AC | 21 ms
12,000 KB |
testcase_45 | AC | 14 ms
11,008 KB |
testcase_46 | AC | 16 ms
11,264 KB |
testcase_47 | AC | 15 ms
10,880 KB |
testcase_48 | AC | 14 ms
11,008 KB |
testcase_49 | AC | 40 ms
13,924 KB |
testcase_50 | AC | 23 ms
12,204 KB |
testcase_51 | AC | 14 ms
11,008 KB |
testcase_52 | AC | 29 ms
12,928 KB |
testcase_53 | AC | 33 ms
13,256 KB |
testcase_54 | AC | 25 ms
12,288 KB |
testcase_55 | AC | 29 ms
12,796 KB |
testcase_56 | AC | 17 ms
11,432 KB |
testcase_57 | AC | 14 ms
11,024 KB |
testcase_58 | AC | 154 ms
33,324 KB |
testcase_59 | AC | 74 ms
18,120 KB |
testcase_60 | AC | 89 ms
18,764 KB |
testcase_61 | AC | 85 ms
19,060 KB |
testcase_62 | AC | 97 ms
20,556 KB |
testcase_63 | AC | 89 ms
19,888 KB |
testcase_64 | AC | 103 ms
22,352 KB |
testcase_65 | AC | 79 ms
18,340 KB |
testcase_66 | AC | 144 ms
29,828 KB |
testcase_67 | AC | 92 ms
19,328 KB |
testcase_68 | RE | - |
testcase_69 | AC | 14 ms
11,008 KB |
testcase_70 | RE | - |
ソースコード
#if __INCLUDE_LEVEL__ == 0 #include __BASE_FILE__ namespace { using Fp = atcoder::modint998244353; Comb<Fp> comb(1e6); void solve() { int n, m; scan(n, m); std::vector<int> l(m), r(m); for (const int i : rep(m)) { scan(l[i], r[i]); --l[i]; } if (n & 1) { print(0); return; } const auto catalan = [&](int n) { return comb.binom(n * 2, n) * comb.recip(n + 1); }; std::vector<std::vector<Fp>> q; for (const int i : rep(m)) { if ((r[i] - l[i]) & 1) { continue; } const int t = (r[i] - l[i]) / 2; q.emplace_back(t + 1); q.back()[0] += 1; q.back()[t] -= catalan(t); } for (int qi = 0; qi + 2 <= len(q); qi += 2) { q.push_back(atcoder::convolution(q[qi], q[qi + 1])); } Fp ans = 0; for (const int i : rep(len(q.back()))) { ans += catalan(n / 2 - i) * q.back()[i]; } print(ans); } } // namespace int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); solve(); } #else // __INCLUDE_LEVEL__ #include <bits/stdc++.h> #include <atcoder/convolution> template <class T> std::vector<T> make_vector_for_overwrite(int n) { static_assert(std::is_trivially_destructible_v<T>); std::vector<T> v; static_assert(sizeof(v) == 3 * sizeof(T*)); v.reserve(n); T*(&a)[3] = reinterpret_cast<T*(&)[3]>(v); assert(a[0] == a[1] && a[1] + n == a[2]); a[1] = a[2]; return v; } template <class T> class Comb { public: Comb() = default; explicit Comb(int max_n) : fact_(make_vector_for_overwrite<T>(max_n + 1)), recip_fact_(make_vector_for_overwrite<T>(max_n + 1)) { fact_[0] = 1; for (const int n : std::views::iota(1, max_n + 1)) { fact_[n] = fact_[n - 1] * n; } recip_fact_[max_n] = 1 / fact_[max_n]; for (const int n : std::views::iota(1, max_n + 1) | std::views::reverse) { recip_fact_[n - 1] = n * recip_fact_[n]; } } T recip(int n) const { assert(n); return n < 0 ? -recip(-n) : recip_fact_[n] * fact_[n - 1]; } T fact(int n) const { assert(0 <= n); return fact_[n]; } T recip_fact(int n) const { return n < 0 ? 0 : recip_fact_[n]; } T falling_fact(int n, int k) const { assert(0 <= n || n < k); if (n < 0) { const T t = falling_fact(k - n - 1, k); return k & 1 ? -t : t; } return n < k ? 0 : recip_fact(n - k) * fact(n); } T recip_falling_fact(int n, int k) const { assert(n < 0 || k <= n); return falling_fact(n - k, -k); } T rising_fact(int n, int k) const { assert(n <= 0 || 0 < n + k); return falling_fact(n + k - 1, k); } T recip_rising_fact(int n, int k) const { assert(0 < n || n + k <= 0); return falling_fact(n - 1, -k); } T binom(int n, int k) const { if ((n < 0) ^ (k < 0) ^ (n < k)) { return 0; } if (n < 0 && k < 0) { k = n - k; } return recip_fact(k) * falling_fact(n, k); } T recip_binom(int n, int k) const { assert((0 <= n) ^ (0 <= k) ^ (k <= n)); k = std::max(k, n - k); return recip_falling_fact(n, k) * fact(k); } T multiset(int n, int k) const { return binom(n + k - 1, k); } T recip_multiset(int n, int k) const { assert((0 < n) ^ (0 <= k) ^ (0 < n + k)); return recip_binom(n + k - 1, k); } private: std::vector<T> fact_; std::vector<T> recip_fact_; }; template <class T, class U = T> bool chmin(T& x, U&& y) { return y < x && (x = std::forward<U>(y), true); } template <class T, class U = T> bool chmax(T& x, U&& y) { return x < y && (x = std::forward<U>(y), true); } template <std::signed_integral T = int> T inf() { T ret; std::memset(&ret, 0x3f, sizeof(ret)); return ret; } template <std::floating_point T> T inf() { return std::numeric_limits<T>::infinity(); } template <class T> concept Range = std::ranges::range<T> && !std::convertible_to<T, std::string_view>; template <class T> concept TupleLike = std::__is_tuple_like<T>::value && !Range<T>; namespace std { istream& operator>>(istream& is, Range auto&& r) { for (auto&& e : r) { is >> e; } return is; } istream& operator>>(istream& is, TupleLike auto&& t) { return apply([&](auto&... xs) -> istream& { return (is >> ... >> xs); }, t); } ostream& operator<<(ostream& os, Range auto&& r) { string_view sep = ""; for (auto&& e : r) { os << exchange(sep, " ") << e; } return os; } ostream& operator<<(ostream& os, TupleLike auto&& t) { const auto f = [&](auto&... xs) -> ostream& { [[maybe_unused]] string_view sep = ""; ((os << exchange(sep, " ") << xs), ...); return os; }; return apply(f, t); } #define DEF_INC_OR_DEC(op) \ auto& operator op(Range auto&& r) { \ for (auto&& e : r) { \ op e; \ } \ return r; \ } \ auto& operator op(TupleLike auto&& t) { \ apply([](auto&... xs) { (op xs, ...); }, t); \ return t; \ } DEF_INC_OR_DEC(++) DEF_INC_OR_DEC(--) #undef DEF_INC_OR_DEC } // namespace std namespace atcoder { template <class T, internal::is_modint_t<T>* = nullptr> std::istream& operator>>(std::istream& is, T& x) { int v; is >> v; x = T::raw(v); return is; } template <class T, internal::is_modint_t<T>* = nullptr> std::ostream& operator<<(std::ostream& os, const T& x) { return os << x.val(); } } // namespace atcoder void scan(auto&&... xs) { std::cin >> std::tie(xs...); } void print(auto&&... xs) { std::cout << std::tie(xs...) << '\n'; } #define FWD(...) static_cast<decltype(__VA_ARGS__)&&>(__VA_ARGS__) template <class F> class fix { public: explicit fix(F f) : f_(std::move(f)) {} decltype(auto) operator()(auto&&... xs) const { return f_(std::ref(*this), FWD(xs)...); } private: F f_; }; template <class T> concept LambdaExpr = std::is_placeholder_v<std::remove_cvref_t<T>> != 0 || std::is_bind_expression_v<std::remove_cvref_t<T>>; auto operator++(LambdaExpr auto&& x, int) { return std::bind([](auto&& x) -> decltype(auto) { return FWD(x)++; }, FWD(x)); } auto operator--(LambdaExpr auto&& x, int) { return std::bind([](auto&& x) -> decltype(auto) { return FWD(x)--; }, FWD(x)); } #define DEF_UNARY_OP(op) \ auto operator op(LambdaExpr auto&& x) { \ return std::bind([](auto&& x) -> decltype(auto) { return op FWD(x); }, FWD(x)); \ } DEF_UNARY_OP(++) DEF_UNARY_OP(--) DEF_UNARY_OP(+) DEF_UNARY_OP(-) DEF_UNARY_OP(~) DEF_UNARY_OP(!) DEF_UNARY_OP(*) DEF_UNARY_OP(&) #undef DEF_UNARY_OP #define DEF_BINARY_OP(op) \ template <class T1, class T2> \ requires LambdaExpr<T1> || LambdaExpr<T2> \ auto operator op(T1&& x, T2&& y) { \ return std::bind([](auto&& x, auto&& y) -> decltype(auto) { return FWD(x) op FWD(y); }, \ FWD(x), FWD(y)); \ } DEF_BINARY_OP(+=) DEF_BINARY_OP(-=) DEF_BINARY_OP(*=) DEF_BINARY_OP(/=) DEF_BINARY_OP(%=) DEF_BINARY_OP(^=) DEF_BINARY_OP(&=) DEF_BINARY_OP(|=) DEF_BINARY_OP(<<=) DEF_BINARY_OP(>>=) DEF_BINARY_OP(+) DEF_BINARY_OP(-) DEF_BINARY_OP(*) DEF_BINARY_OP(/) DEF_BINARY_OP(%) DEF_BINARY_OP(^) DEF_BINARY_OP(&) DEF_BINARY_OP(|) DEF_BINARY_OP(<<) DEF_BINARY_OP(>>) DEF_BINARY_OP(==) DEF_BINARY_OP(!=) DEF_BINARY_OP(<) DEF_BINARY_OP(>) DEF_BINARY_OP(<=) DEF_BINARY_OP(>=) DEF_BINARY_OP(&&) DEF_BINARY_OP(||) #undef DEF_BINARY_OP template <class T1, class T2> requires LambdaExpr<T1> || LambdaExpr<T2> auto at(T1&& x, T2&& y) { return std::bind([](auto&& x, auto&& y) -> decltype(auto) { return FWD(x)[FWD(y)]; }, FWD(x), FWD(y)); } template <int I> auto get(LambdaExpr auto&& x) { return std::bind([](auto&& x) -> decltype(auto) { return std::get<I>(FWD(x)); }, FWD(x)); } inline auto rep(int l, int r) { return std::views::iota(std::min(l, r), r); } inline auto rep(int n) { return rep(0, n); } inline auto rep1(int l, int r) { return rep(l, r + 1); } inline auto rep1(int n) { return rep(1, n + 1); } using namespace std::literals; using namespace std::placeholders; namespace ranges = std::ranges; namespace views = std::views; using i64 = std::int64_t; #define len(...) static_cast<int>(ranges::size(__VA_ARGS__)) #endif // __INCLUDE_LEVEL__