結果
| 問題 | No.623 fudan no modulus to tigau | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-11-22 13:47:26 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 831 bytes | 
| コンパイル時間 | 718 ms | 
| コンパイル使用メモリ | 71,828 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-10-11 02:33:19 | 
| 合計ジャッジ時間 | 1,330 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 12 | 
コンパイルメッセージ
main.cpp: In function 'll f(ll, int)':
main.cpp:21:1: warning: control reaches end of non-void function [-Wreturn-type]
   21 | }
      | ^
            
            ソースコード
#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;
}
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;
}
            
            
            
        