結果

問題 No.623 fudan no modulus to tigau
ユーザー lowrlowr
提出日時 2019-09-26 18:43:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 766 bytes
コンパイル時間 1,985 ms
コンパイル使用メモリ 204,620 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-24 15:39:18
合計ジャッジ時間 5,807 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using i64 = long long;

std::vector<i64> a, b, t, pre;
constexpr i64 mod = 998244353;

i64 rec(int i, i64 x) {
    if (i == 0) return 1;
    if (i == 1) return x;
    if (pre[i] >= 0) return pre[i];
    if (t[i] == 1) return (rec(a[i], x) + rec(b[i], x)) % mod;
    if (t[i] == 2) return a[i] * rec(b[i], x) % mod;
    return rec(a[i], x) * rec(b[i], x) % mod;
}

int main() {
    int n;
    std::cin >> n;
    a.resize(n + 1); b.resize(n + 1); t.resize(n + 1); pre.resize(n + 1);
    for (int i = 2; i <= n; i++) std::cin >> t[i] >> a[i] >> b[i];
    
    int q;
    std::cin >> q;
    while (q--) {
        for (auto &e : pre) e = -1;
        i64 x;
        std::cin >> x;
        std::cout << rec(n, x) << std::endl;
    }
    return 0;
}
0