結果

問題 No.623 fudan no modulus to tigau
ユーザー chocoruskchocorusk
提出日時 2018-12-13 19:19:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 800 bytes
コンパイル時間 752 ms
コンパイル使用メモリ 95,880 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 09:31:08
合計ジャッジ時間 1,834 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=998244353;
int t[51], a[51], b[51], n;
ll solve(ll x){
	ll f[51]; f[0]=1, f[1]=x;
	for(int i=2; i<=n; i++){
		if(t[i]==1) f[i]=(f[a[i]]+f[b[i]])%MOD;
		else if(t[i]==2) f[i]=(ll)a[i]*f[b[i]]%MOD;
		else f[i]=f[a[i]]*f[b[i]]%MOD;
	}
	return f[n];
}
int main()
{
	cin>>n;
	for(int i=2; i<=n; i++) cin>>t[i]>>a[i]>>b[i];
	int q; cin>>q;
	for(int i=0; i<q; i++){
		ll x; cin>>x;
		cout<<solve(x)<<endl;
	}
	return 0;
}
0