結果
| 問題 |
No.623 fudan no modulus to tigau
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-11-22 13:47:43 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 862 bytes |
| コンパイル時間 | 654 ms |
| コンパイル使用メモリ | 71,296 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-11 02:33:20 |
| 合計ジャッジ時間 | 1,299 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 12 |
ソースコード
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
ll t[51], a[51], b[51];
vector<bool> vis(51);
vector<ll> memo(51);
int n;
ll f(ll x, int i){
if(i == 0) return memo[i] = 1;
if(i == 1) return memo[i] = x;
if(vis[i]) return memo[i];
vis[i] = true;
if(t[i] == 1) return memo[i] = (f(x, a[i]) + f(x, b[i]))%mod;
if(t[i] == 2) return memo[i] = a[i]*f(x,b[i])%mod;
if(t[i] == 3) return memo[i] = f(x, a[i])*f(x, b[i])%mod;
return 0; // unreachable
}
int main(){
cin >> n;
for(int i = 2; i <= n; i++){
cin >> t[i] >> a[i] >> b[i];
}
int q;
cin >> q;
while(q-- > 0){
fill(vis.begin(), vis.end(), false);
fill(memo.begin(), memo.end(), 0);
ll x; cin >> x;
cout << f(x, n) << endl;
}
return 0;
}