結果

問題 No.623 fudan no modulus to tigau
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2020-09-09 14:26:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 694 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 86,956 KB
実行使用メモリ 76,420 KB
最終ジャッジ日時 2023-08-21 16:20:07
合計ジャッジ時間 2,316 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
76,168 KB
testcase_01 AC 78 ms
76,340 KB
testcase_02 AC 77 ms
76,420 KB
testcase_03 AC 78 ms
76,240 KB
testcase_04 AC 76 ms
76,188 KB
testcase_05 AC 76 ms
76,188 KB
testcase_06 AC 76 ms
76,192 KB
testcase_07 AC 78 ms
76,188 KB
testcase_08 AC 80 ms
76,192 KB
testcase_09 AC 78 ms
76,128 KB
testcase_10 AC 78 ms
76,360 KB
testcase_11 AC 79 ms
76,232 KB
testcase_12 AC 69 ms
71,380 KB
testcase_13 AC 68 ms
71,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

https://yukicoder.me/problems/no/623

多項式を出すのは大変だが、答えなら別に大変じゃない

"""

from sys import stdin

n = int(stdin.readline())

tab = [None,None]

for i in range(n-1):

    t,a,b = map(int,stdin.readline().split())
    tab.append((t,a,b))

q = int(stdin.readline())
x = list(map(int,stdin.readline().split()))
mod = 998244353

for loop in range(q):

    nx = x[loop]

    f = [1,nx]
    for j in range(2,n+1):
        #print (j)
        t,a,b = tab[j]

        if t == 1:
            f.append(f[a] + f[b])
        elif t == 2:
            f.append(a * f[b])
        else:
            f.append(f[a] * f[b])
        f[-1] %= mod

    print (f[-1])
0