結果

問題 No.623 fudan no modulus to tigau
ユーザー sekiya9311
提出日時 2017-12-23 00:19:01
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 763 bytes
コンパイル時間 1,542 ms
コンパイル使用メモリ 167,244 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-17 23:53:42
合計ジャッジ時間 2,211 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const long long MOD = 998244353;
const int MAX = 55;
long long f[MAX];
int t[MAX], a[MAX], b[MAX];

int main() {
    int n;
    cin >> n;
    for (int i = 2; i <= n; i++) {
        cin >> t[i] >> a[i] >> b[i];
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        long long x;
        cin >> x;
        memset(f, 0, sizeof(f));
        f[0] = 1;
        f[1] = x;
        for (int j = 2; j <= n; j++) {
            if (t[j] == 1) {
                f[j] = (f[a[j]] + f[b[j]]) % MOD;
            } else if (t[j] == 2) {
                f[j] = a[j] * f[b[j]] % MOD;
            } else {
                f[j] = (f[a[j]] * f[b[j]]) % MOD;
            }
        }
        cout << f[n] << endl;
    }
}
0