結果
問題 | No.1241 Eternal Tours |
ユーザー |
![]() |
提出日時 | 2020-08-27 23:58:54 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 247 ms / 6,000 ms |
コード長 | 2,737 bytes |
コンパイル時間 | 1,468 ms |
コンパイル使用メモリ | 72,436 KB |
最終ジャッジ日時 | 2025-01-13 15:51:03 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
#include <cassert> #include <iostream> #include <vector> // O(2^(X + Y)) fast solution template <int mod> struct ModInt { using lint = long long; 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); } 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 { 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; } friend std::ostream &operator<<(std::ostream &os, const ModInt &x) { os << x.val; return os; } constexpr ModInt pow(lint n) const { lint ans = 1, tmp = this->val; n %= (mod - 1); while (n) { if (n & 1) ans = ans * tmp % mod; tmp = tmp * tmp % mod; n /= 2; } return ans; } constexpr ModInt inv() const { return this->pow(mod - 2); } }; constexpr int md = 998244353; using mint = ModInt<md>; int main() { int X, Y; long long T; long long a, b, c, d; std::cin >> X >> Y >> T >> a >> b >> c >> d; mint primitive_root = 3; mint rx = primitive_root.pow((md - 1) / (1 << (X + 1))), rxi = rx.inv(); mint ry = primitive_root.pow((md - 1) / (1 << (Y + 1))), ryi = ry.inv(); mint rxa = rx.pow(a), rxai = rxa.inv(); mint ryb = ry.pow(b), rybi = ryb.inv(); mint rxci = rxi.pow(c); mint rydi = ryi.pow(d); mint rxpow = 1, rxpowi = 1, rypow, rypowi; mint rxapow = 1, rxapowi = 1, rybpow, rybpowi; mint rxcpowi = 1, rydpowi; mint ret = 0; for (int k = 0; k < 1 << (X + 1); k++) { rypow = 1, rypowi = 1; rybpow = 1, rybpowi = 1; rydpowi = 1; for (int l = 0; l < 1 << (Y + 1); l++) { mint fkl = rxpow + rxpowi + rypow + rypowi + 1; mint dp0kl = (rxapow - rxapowi) * (rybpow - rybpowi); ret += fkl.pow(T) * dp0kl * rxcpowi * rydpowi; rypow *= ry, rypowi *= ryi; rybpow *= ryb, rybpowi *= rybi; rydpowi *= rydi; } rxpow *= rx, rxpowi *= rxi; rxapow *= rxa, rxapowi *= rxai; rxcpowi *= rxci; } std::cout << ret * mint(1 << (X + Y + 2)).inv() << '\n'; }