結果
問題 | No.623 fudan no modulus to tigau |
ユーザー |
|
提出日時 | 2018-01-17 09:25:59 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 839 bytes |
コンパイル時間 | 932 ms |
コンパイル使用メモリ | 126,388 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-12 23:34:38 |
合計ジャッジ時間 | 1,416 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 12 |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm;import std.typecons, std.range, std.random, std.math, std.container;import std.numeric, std.bigint, core.bitop;immutable long MOD = 998244353;void main() {auto N = readln.chomp.to!int;auto F = (N-1).iota.map!(_ => readln.split.map!(to!int).array).array;auto Q = readln.chomp.to!int;auto X = readln.split.map!(to!long).array;foreach (x; X) {auto Y = new long[](N+1);Y[0] = 1;Y[1] = x;foreach (i, f; F.enumerate) {if (f[0] == 1) {Y[i+2] = (Y[f[1]] + Y[f[2]]) % MOD;} else if (f[0] == 2) {Y[i+2] = (f[1] * Y[f[2]]) % MOD;} else {Y[i+2] = Y[f[1]] * Y[f[2]] % MOD;}}Y.back.writeln;}}