結果

問題 No.623 fudan no modulus to tigau
ユーザー PachicobuePachicobue
提出日時 2017-12-23 00:53:03
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,034 bytes
コンパイル時間 4,616 ms
コンパイル使用メモリ 203,580 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 15:09:17
合計ジャッジ時間 3,404 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
constexpr ll MOD = 998244353;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> f(N + 1);
    using T = tuple<int, int, int>;
    vector<T> query(N + 1);
    for (int i = 2; i <= N; i++) {
        int t, a, b;
        cin >> t >> a >> b;
        query[i] = make_tuple(t, a, b);
    }
    f[0] = 1;
    int Q;
    cin >> Q;
    for (int q = 0; q < Q; q++) {
        ll x;
        cin >> x;
        f[1] = x;
        for (int i = 2; i <= N; i++) {
            const int t = get<0>(query[i]);
            const int a = get<1>(query[i]);
            const int b = get<2>(query[i]);
            if (t == 1) {
                f[i] = (f[a] + f[b]) % MOD;
            } else if (t == 2) {
                f[i] = (a * f[b]) % MOD;
            } else {
                f[i] = (f[a] * f[b]) % MOD;
            }
        }
        cout << f[N] << endl;
    }
    return 0;
}
0