結果

問題 No.623 fudan no modulus to tigau
ユーザー lumc_lumc_
提出日時 2018-03-22 15:03:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 722 bytes
コンパイル時間 1,678 ms
コンパイル使用メモリ 147,616 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-07 01:30:22
合計ジャッジ時間 2,193 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

ll mod = 998244353;

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n; cin >> n;
  vector<int> t(n + 2), a(n + 2), b(n + 2); 
  for(int i = 2; i <= n; i++) {
    cin >> t[i] >> a[i] >> b[i];
  } 
  int q; cin >> q;
  vector<ll> f(n + 1);
  for(int i = 0; i < q; i++) {
    int x; cin >> x;
    f[0] = 1; f[1] = x;
    for(int i = 2; i <= n; i++) {
      switch(t[i]) {
        case 1:
          f[i] = (f[a[i]] + f[b[i]]) % mod;
          break;
        case 2:
          f[i] = a[i] * f[b[i]] % mod;
          break;
        case 3:
          f[i] = f[a[i]] * f[b[i]] % mod;
          break;
      }
    }
    cout << f[n] << endl;
  }
}
0