結果
問題 | No.2810 Have Another Go (Hard) |
ユーザー | risujiroh |
提出日時 | 2024-07-12 21:45:23 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 231 ms / 3,000 ms |
コード長 | 4,499 bytes |
コンパイル時間 | 3,396 ms |
コンパイル使用メモリ | 256,468 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-12 21:45:40 |
合計ジャッジ時間 | 12,912 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 203 ms
6,944 KB |
testcase_02 | AC | 201 ms
6,944 KB |
testcase_03 | AC | 201 ms
6,940 KB |
testcase_04 | AC | 202 ms
6,940 KB |
testcase_05 | AC | 203 ms
6,944 KB |
testcase_06 | AC | 201 ms
6,944 KB |
testcase_07 | AC | 201 ms
6,940 KB |
testcase_08 | AC | 201 ms
6,940 KB |
testcase_09 | AC | 202 ms
6,940 KB |
testcase_10 | AC | 201 ms
6,944 KB |
testcase_11 | AC | 3 ms
6,944 KB |
testcase_12 | AC | 4 ms
6,940 KB |
testcase_13 | AC | 3 ms
6,944 KB |
testcase_14 | AC | 3 ms
6,940 KB |
testcase_15 | AC | 3 ms
6,944 KB |
testcase_16 | AC | 45 ms
6,944 KB |
testcase_17 | AC | 178 ms
6,940 KB |
testcase_18 | AC | 109 ms
6,948 KB |
testcase_19 | AC | 169 ms
6,944 KB |
testcase_20 | AC | 28 ms
6,940 KB |
testcase_21 | AC | 61 ms
6,944 KB |
testcase_22 | AC | 111 ms
6,944 KB |
testcase_23 | AC | 77 ms
6,940 KB |
testcase_24 | AC | 127 ms
6,940 KB |
testcase_25 | AC | 193 ms
6,940 KB |
testcase_26 | AC | 203 ms
6,940 KB |
testcase_27 | AC | 200 ms
6,940 KB |
testcase_28 | AC | 202 ms
6,940 KB |
testcase_29 | AC | 202 ms
6,940 KB |
testcase_30 | AC | 203 ms
6,940 KB |
testcase_31 | AC | 201 ms
6,944 KB |
testcase_32 | AC | 202 ms
6,944 KB |
testcase_33 | AC | 201 ms
6,940 KB |
testcase_34 | AC | 201 ms
6,944 KB |
testcase_35 | AC | 201 ms
6,940 KB |
testcase_36 | AC | 202 ms
6,940 KB |
testcase_37 | AC | 201 ms
6,944 KB |
testcase_38 | AC | 200 ms
6,940 KB |
testcase_39 | AC | 202 ms
6,940 KB |
testcase_40 | AC | 202 ms
6,944 KB |
testcase_41 | AC | 231 ms
6,944 KB |
testcase_42 | AC | 202 ms
6,944 KB |
testcase_43 | AC | 200 ms
6,940 KB |
testcase_44 | AC | 203 ms
6,940 KB |
testcase_45 | AC | 202 ms
6,944 KB |
testcase_46 | AC | 2 ms
6,944 KB |
testcase_47 | AC | 3 ms
6,944 KB |
testcase_48 | AC | 3 ms
6,940 KB |
testcase_49 | AC | 2 ms
6,944 KB |
testcase_50 | AC | 2 ms
6,944 KB |
testcase_51 | AC | 6 ms
6,944 KB |
testcase_52 | AC | 4 ms
6,944 KB |
testcase_53 | AC | 7 ms
6,944 KB |
testcase_54 | AC | 8 ms
6,940 KB |
testcase_55 | AC | 4 ms
6,944 KB |
testcase_56 | AC | 8 ms
6,940 KB |
testcase_57 | AC | 7 ms
6,940 KB |
testcase_58 | AC | 7 ms
6,940 KB |
testcase_59 | AC | 11 ms
6,944 KB |
testcase_60 | AC | 8 ms
6,940 KB |
ソースコード
#if __INCLUDE_LEVEL__ == 0 #include __BASE_FILE__ namespace { using Mint = atcoder::modint998244353; constexpr Int N = 6; using Vec = std::array<Mint, N>; using Mat = std::array<Vec, N>; Mat operator*(const Mat& x, const Mat& y) { Mat ret{}; for (Int i : Rep(N)) { for (Int k : Rep(N)) { for (Int j : Rep(N)) { ret[i][j] += x[i][k] * y[k][j]; } } } return ret; } Vec operator*(const Mat& x, const Vec& y) { Vec ret{}; for (Int i : Rep(N)) { for (Int j : Rep(N)) { ret[i] += x[i][j] * y[j]; } } return ret; } Mat pow(Mat x, Int n) { if (n == 0) { for (Int i : Rep(N)) { for (Int j : Rep(N)) { x[i][j] = i == j; } } return x; } for (; n % 2 == 0; n >>= 1) { x = x * x; } Mat ret = x; while (n >>= 1) { x = x * x; if (n % 2) { ret = ret * x; } } return ret; } void Solve() { Int n, m, q; Scan(n, m, q); Mat a{}; Mat b{}; a[0].fill(1); for (Int i : Rep(1, N)) { a[i][i - 1] = 1; b[i][i - 1] = 1; } Mint all = 0; { Vec v{}; v[0] = 1; v = pow(a, n * m - 1) * v; for (Int i : Rep(N)) { all += v[i] * (N - i); } } Mat mid = b * pow(pow(a, n - 1) * b, m - 1); while (q--) { Int c; Scan(c); Vec v{}; v[0] = 1; v = pow(a, c - 1) * v; v = mid * v; v = pow(a, n - c - 1) * v; Mint ans = 0; for (Int i : Rep(N)) { ans += v[i] * (N - i); } Print(all - ans); } } } // namespace int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout << std::setprecision(std::numeric_limits<Float>::max_digits10); Solve(); } #else // __INCLUDE_LEVEL__ #include <bits/stdc++.h> #include <atcoder/modint> using Int = int64_t; using Float = double; namespace ranges = std::ranges; namespace views = std::views; inline constexpr auto Rev = views::reverse; inline constexpr auto Map = views::transform; inline constexpr auto Filter = views::filter; constexpr auto Rep(Int l, Int r) { return views::iota(std::min(l, r), r); } constexpr auto Rep(Int n) { return Rep(0, n); } constexpr auto Rep1(Int l, Int r) { return Rep(l, r + 1); } constexpr auto Rep1(Int n) { return Rep(1, n + 1); } constexpr Int Sz(auto&& r) { return static_cast<Int>(ranges::size(r)); } 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); } inline constexpr Int INF = [] { std::array<char, sizeof(Int)> a; a.fill(0x3f); return std::bit_cast<Int>(a); }(); template <class T> concept Range = 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) { for (string_view sep = ""; 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); } template <class T, atcoder::internal::is_modint_t<T>* = nullptr> istream& operator>>(istream& is, T& x) { int v; is >> v; x = T::raw(v); return is; } template <class T, atcoder::internal::is_modint_t<T>* = nullptr> ostream& operator<<(ostream& os, const T& x) { return os << x.val(); } } // namespace std #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) { \ std::apply([](auto&... xs) { (op xs, ...); }, t); \ return t; \ } DEF_INC_OR_DEC(++) DEF_INC_OR_DEC(--) #undef DEF_INC_OR_DEC void Scan(auto&&... xs) { std::cin >> std::tie(xs...); } void Print(auto&&... xs) { std::cout << std::tie(xs...) << '\n'; } 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), std::forward<decltype(xs)>(xs)...); } private: F f_; }; #endif // __INCLUDE_LEVEL__