結果
問題 |
No.623 fudan no modulus to tigau
|
ユーザー |
![]() |
提出日時 | 2018-03-22 15:03:55 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 722 bytes |
コンパイル時間 | 1,208 ms |
コンパイル使用メモリ | 161,372 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-24 20:07:04 |
合計ジャッジ時間 | 1,886 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 12 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; ll mod = 998244353; int main() { ios::sync_with_stdio(false), cin.tie(0); int n; cin >> n; vector<int> t(n + 2), a(n + 2), b(n + 2); for(int i = 2; i <= n; i++) { cin >> t[i] >> a[i] >> b[i]; } int q; cin >> q; vector<ll> f(n + 1); for(int i = 0; i < q; i++) { int x; cin >> x; f[0] = 1; f[1] = x; for(int i = 2; i <= n; i++) { switch(t[i]) { case 1: f[i] = (f[a[i]] + f[b[i]]) % mod; break; case 2: f[i] = a[i] * f[b[i]] % mod; break; case 3: f[i] = f[a[i]] * f[b[i]] % mod; break; } } cout << f[n] << endl; } }