結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 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
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'll f(ll, int)':
main.cpp:21:1: warning: control reaches end of non-void function [-Wreturn-type]
   21 | }
      | ^

ソースコード

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;
}

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