結果

問題 No.623 fudan no modulus to tigau
ユーザー face4face4
提出日時 2019-11-22 13:47:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 862 bytes
コンパイル時間 656 ms
コンパイル使用メモリ 71,924 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 10:12:54
合計ジャッジ時間 1,188 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

const ll mod = 998244353;

ll t[51], a[51], b[51];
vector<bool> vis(51);
vector<ll> memo(51);
int n;

ll f(ll x, int i){
    if(i == 0)  return memo[i] = 1;
    if(i == 1)  return memo[i] = x;
    if(vis[i])  return memo[i];
    vis[i] = true;
    if(t[i] == 1)   return memo[i] = (f(x, a[i]) + f(x, b[i]))%mod;
    if(t[i] == 2)   return memo[i] = a[i]*f(x,b[i])%mod;
    if(t[i] == 3)   return memo[i] = f(x, a[i])*f(x, b[i])%mod;
    return 0;   // unreachable
}

int main(){
    cin >> n;
    for(int i = 2; i <= n; i++){
        cin >> t[i] >> a[i] >> b[i];
    }
    int q;
    cin >> q;
    while(q-- > 0){
        fill(vis.begin(), vis.end(), false);
        fill(memo.begin(), memo.end(), 0);
        ll x;   cin >> x;
        cout << f(x, n) << endl;
    }
    return 0;
}
0