結果

問題 No.623 fudan no modulus to tigau
ユーザー kenta255kenta255
提出日時 2022-01-27 23:45:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 552 bytes
コンパイル時間 2,051 ms
コンパイル使用メモリ 200,684 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-27 02:21:48
合計ジャッジ時間 3,120 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=998244353;
mt19937_64 mt(30);

int main(){
	ll N,q;
	cin >> N;
	vector<ll> t(N+1),a(N+1),b(N+1);
	for(int i=2;i<=N;i++){
		cin >> t[i] >> a[i] >> b[i];
	}
	cin >> q;

	for(int i=0;i<q;i++){
		ll x;
		cin >> x;
		vector<ll> f(N+1,1);
		f[1] = x;
		for(int j=2;j<=N;j++){
			if(t[j] == 1){
				f[j] = ( f[a[j]] + f[b[j]] ) % MOD;
			}else if(t[j] == 2){
				f[j] = a[j] * f[b[j]] % MOD;
			}else{
				f[j] = f[a[j]] * f[b[j]] % MOD;
			}
		}
		cout << f[N] << endl;
	}

}

0