結果
| 問題 |
No.1241 Eternal Tours
|
| コンテスト | |
| ユーザー |
hitonanode
|
| 提出日時 | 2020-08-28 00:51:32 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 56 ms / 6,000 ms |
| コード長 | 2,808 bytes |
| コンパイル時間 | 781 ms |
| コンパイル使用メモリ | 72,688 KB |
| 最終ジャッジ日時 | 2025-01-13 15:52:27 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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 rxc = rx.pow(c), rxci = rxc.inv();
mint ryd = ry.pow(d), rydi = ryd.inv();
mint rxpow = 1, rxpowi = 1, rypow, rypowi;
mint rxapow = 1, rxapowi = 1, rybpow, rybpowi;
mint rxcpow = 1, rxcpowi = 1, rydpow, rydpowi;
mint ret = 0;
for (int k = 0; k < 1 << X; k++)
{
rypow = 1, rypowi = 1;
rybpow = 1, rybpowi = 1;
rydpow = 1, rydpowi = 1;
for (int l = 0; l < 1 << Y; l++)
{
mint fkl = rxpow + rxpowi + rypow + rypowi + 1;
ret += fkl.pow(T) * (rxapow - rxapowi) * (rybpow - rybpowi) * (rxcpow - rxcpowi) * (rydpow - rydpowi);
rypow *= ry, rypowi *= ryi;
rybpow *= ryb, rybpowi *= rybi;
rydpow *= ryd, rydpowi *= rydi;
}
rxpow *= rx, rxpowi *= rxi;
rxapow *= rxa, rxapowi *= rxai;
rxcpow *= rxc, rxcpowi *= rxci;
}
std::cout << ret * mint(1 << (X + Y + 2)).inv() << '\n';
}
hitonanode