結果

問題 No.623 fudan no modulus to tigau
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2020-09-09 14:26:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 694 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 82,592 KB
実行使用メモリ 61,860 KB
最終ジャッジ日時 2024-12-15 05:31:31
合計ジャッジ時間 1,488 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
61,224 KB
testcase_01 AC 44 ms
59,892 KB
testcase_02 AC 43 ms
60,280 KB
testcase_03 AC 45 ms
60,680 KB
testcase_04 AC 45 ms
59,220 KB
testcase_05 AC 43 ms
59,216 KB
testcase_06 AC 43 ms
59,372 KB
testcase_07 AC 46 ms
61,476 KB
testcase_08 AC 46 ms
61,812 KB
testcase_09 AC 45 ms
59,784 KB
testcase_10 AC 46 ms
61,000 KB
testcase_11 AC 46 ms
61,860 KB
testcase_12 AC 37 ms
53,288 KB
testcase_13 AC 38 ms
52,552 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