結果
| 問題 | No.623 fudan no modulus to tigau |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-12-23 00:27:22 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,005 bytes |
| 記録 | |
| コンパイル時間 | 772 ms |
| コンパイル使用メモリ | 76,800 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-17 14:20:26 |
| 合計ジャッジ時間 | 5,985 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 11 WA * 1 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int mod = 998244353;
const int g = 3;
const int N = 1 << 12;
struct Modint {
int n;
Modint(int n = 0) : n(n) {}
};
Modint operator+(Modint a, Modint b) { return Modint((a.n += b.n) >= mod ? a.n - mod : a.n); }
Modint operator-(Modint a, Modint b) { return Modint((a.n -= b.n) < 0 ? a.n + mod : a.n); }
Modint operator*(Modint a, Modint b) { return Modint(1LL * a.n * b.n % mod); }
Modint &operator+=(Modint &a, Modint b) { return a = a + b; }
Modint &operator-=(Modint &a, Modint b) { return a = a - b; }
Modint &operator*=(Modint &a, Modint b) { return a = a * b; }
Modint modpow(Modint a, long long b) {
Modint res = 1;
while (b > 0) {
if (b & 1) res *= a;
a *= a;
b >>= 1;
}
return res;
}
vector<Modint> ntt(vector<Modint> a, bool rev = false) {
vector<Modint> res(N);
Modint w = modpow(g, (mod - 1) / N);
if (rev) w = modpow(w, mod - 2);
for (int i = 0; i < N; i++) {
Modint ws = 1;
Modint u = modpow(w, i);
for (int j = 0; j < N; j++) {
res[i] += a[j] * ws;
ws *= u;
}
}
if (rev) {
for (int i = 0; i < N; i++) {
res[i] *= modpow(N, mod - 2);
}
}
return res;
}
int main() {
int n;
cin >> n;
vector<vector<Modint>> f(n + 1, vector<Modint>(N));
f[0][0] = 1;
f[1][1] = 1;
f[0] = ntt(f[0]);
f[1] = ntt(f[1]);
for (int i = 2; i <= n; i++) {
int t, a, b;
cin >> t >> a >> b;
if (t == 1) {
for (int j = 0; j < N; j++) {
f[i][j] = f[a][j] + f[b][j];
}
} else if (t == 2) {
for (int j = 0; j < N; j++) {
f[i][j] = a * f[b][j];
}
} else {
for (int j = 0; j < N; j++) {
f[i][j] = f[a][j] * f[b][j];
}
}
}
f[n] = ntt(f[n], true);
int q;
cin >> q;
while (q--) {
Modint x;
cin >> x.n;
Modint res = 0;
for (int i = N - 1; i >= 0; i--) {
res = res * x + f[n][i];
}
cout << res.n << endl;
}
}