結果

問題 No.1241 Eternal Tours
ユーザー rabimearabimea
提出日時 2023-01-27 06:35:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 817 ms / 6,000 ms
コード長 2,303 bytes
コンパイル時間 1,868 ms
コンパイル使用メモリ 199,256 KB
最終ジャッジ日時 2025-02-10 07:22:02
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
using vi = vector <int>;
using ll = long long;
using vl = vector <ll>;
using pii = pair <int, int>;
const ll mod = 998244353;
//~ const ll mod = 1e9 + 7;
ll qpow(ll a, ll b, ll m = mod) { ll r = 1, t = a;
	for(; b; b /= 2) { if(b & 1) r = r * t % m; t = t * t % m; } return r; }

const ll P = mod, G = 3;
ll INV(ll x) { return qpow(x, P - 2); }
void ntt(vl &a, int op = 1) { // P: 模数, G: 原根
	int n = a.size();
	for (int i = 1, j = 0; i < n - 1; ++i) {
		for (int s = n; j ^= s >>= 1, ~j & s;) {}
		if (i < j) swap(a[i], a[j]);
	}
	for (int i = 1; i < n; i *= 2) {
		ll u = qpow(G, (P - 1) / (i * 2));
		if (op == -1) u = INV(u);
		for (int j = 0; j < n; j += i * 2) {
			ll w = 1;
			for (int k = 0; k < i; ++k, w = w * u % P) {
				int x = a[j + k], y = w * a[j + k + i] % P;
				#define modto(x) ({if ((x) >= P) (x) -= P;})
				a[j + k] = x + y; modto(a[j + k]);
				a[j + k + i] = x - y + P; modto(a[j + k + i]);
				#undef modto
	}}}
	if (op == -1) { ll inv = INV(n);
		for (int i = 0; i < n; ++i) a[i] = a[i] * inv % P; }
}

void ntt2d(vector<vl> &mat)
{
    for (auto &vec : mat) ntt(vec);
    int h = mat.size(), w = mat[0].size();
    for (int j = 0; j < w; j++)
    {
        vl v(h);
        for (int i = 0; i < h; i++) v[i] = mat[i][j];
        ntt(v);
        for (int i = 0; i < h; i++) mat[i][j] = v[i];
    }
}
void ntt2dinv(vector<vl> &mat)
{
    int h = mat.size(), w = mat[0].size();
    for (int j = 0; j < w; j++)
    {
        vl v(h);
        for (int i = 0; i < h; i++) v[i] = mat[i][j];
        ntt(v, -1);
        for (int i = 0; i < h; i++) mat[i][j] = v[i];
    }
    for (auto &vec : mat) ntt(vec, -1);
}

int main() {
	ios :: sync_with_stdio(false);
	
	int x, y; cin >> x >> y;
	ll t; cin >> t;
	int a, b, c, d; cin >> a >> b >> c >> d;
	
	int n = (1 << (x + 1));
	int m = (1 << (y + 1));
	
	vector <vl> f(n, vl(m));
	f[0][0] = f[0][1] = f[1][0] = f[n - 1][0] = f[0][m - 1] = 1;
	
	vector <vl> g(n, vl(m));
	g[a][b] = g[n - a][m - b] = 1;
	g[n - a][b] = g[a][m - b] = mod - 1;
	
	ntt2d(f); ntt2d(g);
	
	for(int i = 0; i < n; i ++)
		for(int j = 0; j < m; j ++) {
			g[i][j] *= qpow(f[i][j], t);
			g[i][j] %= mod;
		}
	ntt2dinv(g);
	
	cout << g[c][d] << '\n';
}
0