結果
問題 |
No.623 fudan no modulus to tigau
|
ユーザー |
|
提出日時 | 2017-12-26 16:03:54 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 767 bytes |
コンパイル時間 | 1,947 ms |
コンパイル使用メモリ | 196,168 KB |
最終ジャッジ日時 | 2025-01-05 06:31:28 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 12 |
ソースコード
#include <bits/stdc++.h> const int MOD = 998244353; signed main() { std::ios::sync_with_stdio(false); int N; std::cin >> N; std::vector<int> T(N + 1), A(N + 1), B(N + 1); for (int i = 2; i <= N; ++i) { std::cin >> T[i] >> A[i] >> B[i]; } int Q; std::cin >> Q; while (Q--) { int X; std::cin >> X; std::vector<int> dp(N + 1, -1); std::function<int(int, int)> f = [&](int n, int x) { if (n == 0) return 1; if (n == 1) return x; if (~dp[n]) return dp[n]; if (T[n] == 1) return dp[n] = (f(A[n], x) + f(B[n], x)) % MOD; if (T[n] == 2) return dp[n] = 1LL * A[n] * f(B[n], x) % MOD; return dp[n] = 1LL * f(A[n], x) * f(B[n], x) % MOD; }; std::cout << f(N, X) << std::endl; } return 0; }