結果

問題 No.623 fudan no modulus to tigau
ユーザー WA_TLEWA_TLE
提出日時 2017-12-23 00:14:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,109 bytes
コンパイル時間 1,222 ms
コンパイル使用メモリ 115,212 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 21:34:54
合計ジャッジ時間 2,058 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<map>
#include<functional>
using namespace std;
typedef long long int llint;
typedef bool izryt;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const int big=1e9;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
const llint mod=998244353;
//なにがNTTだ!
int main(void){
	int n;cin>>n;
	vector<tuple<int,int,int>>que(n-1);
	for(auto &it:que){cin>>get<0>(it)>>get<1>(it)>>get<2>(it);}
	int q;cin>>q;
	vector<llint>ans(n+1);
	while(q--){
		llint x;cin>>x;ans[0]=1;ans[1]=x;
		for(int i=0;i<n-1;i++){
			int t,a,b;tie(t,a,b)=que[i];
			if(t==1){ans[i+2]=ans[a]+ans[b];}
			if(t==2){ans[i+2]=a*ans[b];}
			if(t==3){ans[i+2]=ans[a]*ans[b];}
			ans[i+2]%=mod;
		}
		cout<<ans[n]<<endl;
	}
	return 0;
}
0