結果
| 問題 | No.623 fudan no modulus to tigau | 
| コンテスト | |
| ユーザー |  merom686 | 
| 提出日時 | 2017-12-23 00:18:09 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 805 bytes | 
| コンパイル時間 | 768 ms | 
| コンパイル使用メモリ | 73,580 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-12-17 23:53:37 | 
| 合計ジャッジ時間 | 1,340 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 12 | 
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int main() {
    int n;
    cin >> n;
    int t[51], a[51], b[51];
    for (int i = 2; i <= n; i++) {
        cin >> t[i] >> a[i] >> b[i];
    }
    int q;
    cin >> q;
    int64_t f[51];
    for (int i = 0; i < q; i++) {
        int x;
        cin >> x;
        f[0] = 1;
        f[1] = x;
        for (int i = 2; i <= n; i++) {
            if (t[i] == 1) {
                f[i] = f[a[i]] + f[b[i]];
            } else if (t[i] == 2) {
                f[i] = a[i] * f[b[i]];
            } else {
                f[i] = f[a[i]] * f[b[i]];
            }
            f[i] %= 998244353;
        }
        cout << f[n] << '\n';
    }
    return 0;
}
            
            
            
        