結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 2 ms
5,376 KB
testcase_10 AC 2 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 <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;
}
0