結果

問題 No.623 fudan no modulus to tigau
ユーザー hiroakiehiroakie
提出日時 2017-12-23 10:19:08
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 697 bytes
コンパイル時間 580 ms
コンパイル使用メモリ 58,676 KB
実行使用メモリ 13,880 KB
最終ジャッジ日時 2024-05-09 22:10:27
合計ジャッジ時間 4,221 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
13,880 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long int ll;
const ll MOD = 998244353;
struct func { int t, a, b; };
func F[51];
int n,q;

ll fnct(ll ind, ll par) {
	if (ind == 0)return 1;
	if (ind == 1)return par;
	if (F[ind].t == 1)return (fnct(F[ind].a, par) + fnct(F[ind].b, par))%MOD;
	if (F[ind].t == 2)return (F[ind].a*fnct(F[ind].b, par)) % MOD;
	return (fnct(F[ind].a, par) * fnct(F[ind].b, par)) % MOD;;
}

int main() {
	cin >> n;
	for (int i = 2; i <= n; i++) {
		cin >> F[i].t >> F[i].a >> F[i].b;
		F[i].a %= MOD; F[i].b %= MOD;
	}
	cin >> q;
	for (int i = 0; i < q; i++) {
		int x; cin >> x;
		cout << fnct(n, x) << endl;
	}
	return 0;
}
0