結果

問題 No.623 fudan no modulus to tigau
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2023-08-01 23:47:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 679 bytes
コンパイル時間 222 ms
コンパイル使用メモリ 82,288 KB
実行使用メモリ 65,340 KB
最終ジャッジ日時 2024-04-20 00:25:41
合計ジャッジ時間 1,666 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
63,212 KB
testcase_01 AC 47 ms
63,060 KB
testcase_02 AC 47 ms
62,684 KB
testcase_03 AC 47 ms
62,680 KB
testcase_04 AC 47 ms
62,988 KB
testcase_05 AC 45 ms
63,548 KB
testcase_06 AC 48 ms
62,628 KB
testcase_07 AC 49 ms
64,296 KB
testcase_08 AC 55 ms
65,340 KB
testcase_09 AC 47 ms
63,096 KB
testcase_10 AC 49 ms
63,320 KB
testcase_11 AC 48 ms
64,328 KB
testcase_12 AC 42 ms
55,672 KB
testcase_13 AC 43 ms
55,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline

mod = 998244353
n = int(input())
op = [tuple(map(int,input().split())) for _ in range(n-1)]
def f(q):
    val = [0]*(n+1)
    val[0] = 1
    val[1] = q
    idx = 2
    for t,a,b in op:
        if t==1:
            val[idx] = val[a]+val[b]
            val[idx] %= mod
        elif t==2:
            val[idx] = a*val[b]
            val[idx] %= mod
        else:
            val[idx] = val[a]*val[b]
            val[idx] %= mod
        idx += 1
    return val[-1]

q = int(input())
X = list(map(int,input().split()))
for x in X:
    print(f(x))
0