結果

問題 No.623 fudan no modulus to tigau
ユーザー sekiya9311sekiya9311
提出日時 2017-12-23 00:19:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 763 bytes
コンパイル時間 1,495 ms
コンパイル使用メモリ 166,324 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-10 03:11:38
合計ジャッジ時間 1,876 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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