結果
問題 | No.1241 Eternal Tours |
ユーザー | hitonanode |
提出日時 | 2020-08-27 22:23:42 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 548 ms / 6,000 ms |
コード長 | 5,654 bytes |
コンパイル時間 | 890 ms |
コンパイル使用メモリ | 83,104 KB |
実行使用メモリ | 34,400 KB |
最終ジャッジ日時 | 2024-11-29 10:55:37 |
合計ジャッジ時間 | 10,033 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 136 ms
11,776 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 2 ms
6,820 KB |
testcase_05 | AC | 2 ms
6,820 KB |
testcase_06 | AC | 2 ms
6,820 KB |
testcase_07 | AC | 2 ms
6,816 KB |
testcase_08 | AC | 2 ms
6,820 KB |
testcase_09 | AC | 1 ms
6,820 KB |
testcase_10 | AC | 2 ms
6,820 KB |
testcase_11 | AC | 2 ms
6,816 KB |
testcase_12 | AC | 1 ms
6,816 KB |
testcase_13 | AC | 2 ms
6,816 KB |
testcase_14 | AC | 231 ms
8,064 KB |
testcase_15 | AC | 2 ms
6,820 KB |
testcase_16 | AC | 57 ms
6,820 KB |
testcase_17 | AC | 547 ms
34,400 KB |
testcase_18 | AC | 487 ms
14,336 KB |
testcase_19 | AC | 453 ms
11,788 KB |
testcase_20 | AC | 4 ms
6,816 KB |
testcase_21 | AC | 10 ms
6,820 KB |
testcase_22 | AC | 495 ms
22,924 KB |
testcase_23 | AC | 16 ms
6,820 KB |
testcase_24 | AC | 2 ms
6,820 KB |
testcase_25 | AC | 2 ms
6,816 KB |
testcase_26 | AC | 2 ms
6,816 KB |
testcase_27 | AC | 1 ms
6,816 KB |
testcase_28 | AC | 279 ms
11,648 KB |
testcase_29 | AC | 280 ms
11,776 KB |
testcase_30 | AC | 337 ms
11,904 KB |
testcase_31 | AC | 220 ms
7,552 KB |
testcase_32 | AC | 548 ms
34,272 KB |
testcase_33 | AC | 511 ms
13,012 KB |
testcase_34 | AC | 452 ms
11,776 KB |
testcase_35 | AC | 449 ms
11,648 KB |
testcase_36 | AC | 2 ms
6,816 KB |
testcase_37 | AC | 2 ms
6,816 KB |
testcase_38 | AC | 531 ms
13,016 KB |
testcase_39 | AC | 495 ms
12,260 KB |
testcase_40 | AC | 469 ms
11,776 KB |
testcase_41 | AC | 387 ms
34,400 KB |
testcase_42 | AC | 318 ms
12,392 KB |
testcase_43 | AC | 291 ms
11,648 KB |
ソースコード
#include <cassert> #include <iostream> #include <vector> // 想定解(式をeditorialと一致させた) template <int mod> struct ModInt { using lint = long long; static int get_mod() { return mod; } static int get_primitive_root() { assert(mod == 998244353); return 3; } int val; constexpr ModInt() : val(0) {} constexpr ModInt &_setval(lint v) { val = (v >= mod ? v - mod : v); return *this; } constexpr ModInt(lint v) { _setval(v % mod + mod); } explicit operator bool() const { return val != 0; } constexpr ModInt operator+(const ModInt &x) const { return ModInt()._setval((lint)val + x.val); } constexpr ModInt operator-(const ModInt &x) const { return ModInt()._setval((lint)val - x.val + mod); } constexpr ModInt operator*(const ModInt &x) const { return ModInt()._setval((lint)val * x.val % mod); } constexpr ModInt operator/(const ModInt &x) const { return ModInt()._setval((lint)val * x.inv() % mod); } constexpr ModInt operator-() const { return ModInt()._setval(mod - val); } constexpr ModInt &operator+=(const ModInt &x) { return *this = *this + x; } constexpr ModInt &operator-=(const ModInt &x) { return *this = *this - x; } constexpr ModInt &operator*=(const ModInt &x) { return *this = *this * x; } constexpr ModInt &operator/=(const ModInt &x) { return *this = *this / x; } friend constexpr ModInt operator+(lint a, const ModInt &x) { return ModInt()._setval(a % mod + x.val); } friend constexpr ModInt operator-(lint a, const ModInt &x) { return ModInt()._setval(a % mod - x.val + mod); } friend constexpr ModInt operator*(lint a, const ModInt &x) { return ModInt()._setval(a % mod * x.val % mod); } friend constexpr ModInt operator/(lint a, const ModInt &x) { return ModInt()._setval(a % mod * x.inv() % mod); } constexpr bool operator==(const ModInt &x) const { return val == x.val; } constexpr bool operator!=(const ModInt &x) const { return val != x.val; } friend std::istream &operator>>(std::istream &is, ModInt &x) { lint t; is >> t; x = ModInt(t); return is; } friend std::ostream &operator<<(std::ostream &os, const ModInt &x) { os << x.val; return os; } constexpr lint power(lint n) const { lint ans = 1, tmp = this->val; while (n) { if (n & 1) ans = ans * tmp % mod; tmp = tmp * tmp % mod; n /= 2; } return ans; } constexpr lint inv() const { return this->power(mod - 2); } }; template <typename MODINT> void ntt(std::vector<MODINT> &a, bool is_inverse = false) { int n = a.size(); if (n == 1) return; static const int mod = MODINT::get_mod(); static const MODINT root = MODINT::get_primitive_root(); assert(__builtin_popcount(n) == 1 and (mod - 1) % n == 0); static std::vector<MODINT> w{1}, iw{1}; for (int m = w.size(); m < n / 2; m *= 2) { MODINT dw = root.power((mod - 1) / (4 * m)), dwinv = 1 / dw; w.resize(m * 2), iw.resize(m * 2); for (int i = 0; i < m; i++) w[m + i] = w[i] * dw, iw[m + i] = iw[i] * dwinv; } if (!is_inverse) { for (int m = n; m >>= 1;) { for (int s = 0, k = 0; s < n; s += 2 * m, k++) { for (int i = s; i < s + m; i++) { MODINT x = a[i], y = a[i + m] * w[k]; a[i] = x + y, a[i + m] = x - y; } } } } else { for (int m = 1; m < n; m *= 2) { for (int s = 0, k = 0; s < n; s += 2 * m, k++) { for (int i = s; i < s + m; i++) { MODINT x = a[i], y = a[i + m]; a[i] = x + y, a[i + m] = (x - y) * iw[k]; } } } int n_inv = MODINT(n).inv(); for (auto &v : a) v *= n_inv; } } template <typename MODINT> void ntt2d(std::vector<std::vector<MODINT>> &mat) { for (auto &vec : mat) ntt(vec, false); int h = mat.size(), w = mat[0].size(); for (int j = 0; j < w; j++) { std::vector<MODINT> v(h); for (int i = 0; i < h; i++) v[i] = mat[i][j]; ntt(v, false); for (int i = 0; i < h; i++) mat[i][j] = v[i]; } } template <typename MODINT> void ntt2dinv(std::vector<std::vector<MODINT>> &mat) { int h = mat.size(), w = mat[0].size(); for (int j = 0; j < w; j++) { std::vector<MODINT> v(h); for (int i = 0; i < h; i++) v[i] = mat[i][j]; ntt(v, true); for (int i = 0; i < h; i++) mat[i][j] = v[i]; } for (auto &vec : mat) ntt(vec, true); } using namespace std; using mint = ModInt<998244353>; int main() { int X, Y; long long T; int a, b, c, d; cin >> X >> Y >> T >> a >> b >> c >> d; assert(X >= 1 and Y >= 1); assert(X + Y <= 18); assert(T >= 1 and T <= 1'000'000'000'000'000'000LL); assert(a >= 1 and a < (1 << X)); assert(b >= 1 and b < (1 << Y)); assert(c >= 1 and c < (1 << X)); assert(d >= 1 and d < (1 << Y)); vector dp(1 << (X + 1), vector<mint>(1 << (Y + 1))); dp[a][b] = 1; dp[(1 << (X + 1)) - a][(1 << (Y + 1)) - b] = 1; dp[(1 << (X + 1)) - a][b] = -1; dp[a][(1 << (Y + 1)) - b] = -1; vector trans(1 << (X + 1), vector<mint>(1 << (Y + 1))); trans[0][0] = trans[0][1] = trans[0][(1 << (Y + 1)) - 1] = trans[1][0] = trans[(1 << (X + 1)) - 1][0] = 1; ntt2d(dp); ntt2d(trans); for (size_t i = 0; i < dp.size(); i++) { for (size_t j = 0; j < dp[i].size(); j++) { dp[i][j] *= trans[i][j].power(T); } } ntt2dinv(dp); cout << dp[c][d] << '\n'; }