結果

問題 No.623 fudan no modulus to tigau
ユーザー 👑 obakyanobakyan
提出日時 2019-05-06 11:35:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 966 bytes
コンパイル時間 1,324 ms
コンパイル使用メモリ 74,720 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-09 13:39:00
合計ジャッジ時間 2,265 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cstddef>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <iomanip>
#include <numeric>
#define L64 long long
#define MOD (998244353LL)

int main(void)
{
  int n;
  std::cin >> n;
  std::vector<int> t(n + 1);
  std::vector<int> a(n + 1);
  std::vector<int> b(n + 1);
  for (int i = 2; i <= n; i++){
    std::cin >> t[i] >> a[i] >> b[i];
  }
  int q; std::cin >> q;
  for (int i_q = 1; i_q <= q; i_q++){
    L64 x; std::cin >> x;
    std::vector<L64> f(n + 1);
    f[0] = 1; f[1] = x;
    for (int i_n = 2; i_n <= n; i_n++){
      switch(t[i_n]){
        case 1:
          f[i_n] = (f[a[i_n]] + f[b[i_n]]) % MOD;
        break;
        case 2:
          f[i_n] = ((L64)a[i_n] * f[b[i_n]]) % MOD;
        break;
        case 3:
          f[i_n] = (f[a[i_n]] * f[b[i_n]]) % MOD;
        break;
      }
    }
    std::cout << f[n] << std::endl;
  }
}
0