結果

問題 No.623 fudan no modulus to tigau
ユーザー ayaoniayaoni
提出日時 2020-12-13 00:37:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 872 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 81,656 KB
実行使用メモリ 77,228 KB
最終ジャッジ日時 2023-10-20 02:49:50
合計ジャッジ時間 1,813 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
65,080 KB
testcase_01 AC 59 ms
65,080 KB
testcase_02 AC 60 ms
65,080 KB
testcase_03 AC 60 ms
65,080 KB
testcase_04 AC 61 ms
65,080 KB
testcase_05 AC 77 ms
74,220 KB
testcase_06 AC 97 ms
77,228 KB
testcase_07 AC 54 ms
63,036 KB
testcase_08 AC 58 ms
65,084 KB
testcase_09 AC 56 ms
63,036 KB
testcase_10 AC 55 ms
63,036 KB
testcase_11 AC 52 ms
57,584 KB
testcase_12 AC 48 ms
55,536 KB
testcase_13 AC 48 ms
55,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from functools import lru_cache
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


N = I()
TAB = [(0,0,0)]*2+[tuple(MI()) for _ in range(N-1)]
Q = I()
X = LI()
mod = 998244353


@lru_cache(maxsize=1000)
def f(i,x):
    if i == 0:
        return 1
    if i == 1:
        return x
    t,a,b = TAB[i]
    if t == 1:
        res = f(a,x)+f(b,x)
    elif t == 2:
        res = a*f(b,x)
    else:
        res = f(a,x)*f(b,x)
    return res % mod


for x in X:
    print(f(N,x))
0