結果

問題 No.623 fudan no modulus to tigau
ユーザー yuppe19 😺yuppe19 😺
提出日時 2017-12-23 15:07:34
言語 Python2
(2.7.18)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 663 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 6,684 KB
実行使用メモリ 6,120 KB
最終ジャッジ日時 2023-08-22 16:26:26
合計ジャッジ時間 1,055 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
6,008 KB
testcase_01 AC 13 ms
6,032 KB
testcase_02 AC 13 ms
6,008 KB
testcase_03 AC 12 ms
5,960 KB
testcase_04 AC 12 ms
5,960 KB
testcase_05 AC 12 ms
6,044 KB
testcase_06 AC 12 ms
6,076 KB
testcase_07 AC 12 ms
6,120 KB
testcase_08 AC 12 ms
5,896 KB
testcase_09 AC 12 ms
6,108 KB
testcase_10 AC 12 ms
5,892 KB
testcase_11 AC 12 ms
5,884 KB
testcase_12 AC 12 ms
5,880 KB
testcase_13 AC 11 ms
5,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python2
# -*- coding: utf-8 -*-
# †
mod = 998244353
n = int(raw_input())
T = [None] * (n+1)
A = [None] * (n+1)
B = [None] * (n+1)
for i in xrange(2, n+1):
    T[i], A[i], B[i] = map(int, raw_input().split())

def f(x):
    # dp[i] := fi(x)
    dp = [0] * (n+2)
    dp[0] = 1
    dp[1] = x
    for i in xrange(2, n+1):
        t, a, b = T[i], A[i], B[i]
        if t == 1:
            dp[i] = dp[a] + dp[b]
        elif t == 2:
            dp[i] = a * dp[b]
        elif t == 3:
            dp[i] = dp[a] * dp[b]
        dp[i] %= mod
    return dp[n]


q = int(raw_input())
xs = map(int, raw_input().split())
for x in xs:
    res = f(x)
    print res
0