結果
問題 | No.623 fudan no modulus to tigau |
ユーザー |
![]() |
提出日時 | 2020-12-13 00:37:26 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 78 ms / 2,000 ms |
コード長 | 872 bytes |
コンパイル時間 | 140 ms |
コンパイル使用メモリ | 82,116 KB |
実行使用メモリ | 77,484 KB |
最終ジャッジ日時 | 2024-09-19 22:35:48 |
合計ジャッジ時間 | 1,432 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 12 |
ソースコード
import sysfrom functools import lru_cachesys.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 1if i == 1:return xt,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 % modfor x in X:print(f(N,x))