結果

問題 No.623 fudan no modulus to tigau
ユーザー akakimidoriakakimidori
提出日時 2018-01-11 05:29:40
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 630 bytes
コンパイル時間 1,299 ms
コンパイル使用メモリ 25,148 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-25 10:46:34
合計ジャッジ時間 2,084 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>

typedef long long int int64;

const int mod=998244353;

void run(void){
  int n;
  scanf("%d",&n);
  int t[51];
  int a[51];
  int b[51];
  int i;
  for(i=2;i<=n;i++){
    scanf("%d%d%d",t+i,a+i,b+i);
  }
  int64 f[51];
  f[0]=1;
  int q;
  scanf("%d",&q);
  for(i=1;i<=q;i++){
    int x;
    scanf("%d",&x);
    f[1]=x;
    int k;
    for(k=2;k<=n;k++){
      if(t[k]==1){
	f[k]=(f[a[k]]+f[b[k]])%mod;
      } else if(t[k]==2){
	f[k]=a[k]*f[b[k]]%mod;
      } else {
	f[k]=f[a[k]]*f[b[k]]%mod;
      }
    }
    printf("%lld\n",f[n]);
  }
  return;
}

int main(void){
  run();
  return 0;
}
0