結果
問題 | No.623 fudan no modulus to tigau |
ユーザー | Sooh317 |
提出日時 | 2022-02-21 12:20:13 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 3,495 bytes |
コンパイル時間 | 2,053 ms |
コンパイル使用メモリ | 214,600 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-29 16:42:42 |
合計ジャッジ時間 | 2,934 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 1 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 1 ms
6,944 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 1 ms
6,940 KB |
ソースコード
/** * author: Sooh * created: 20.02.2022 20:58:25 **/ #include<bits/stdc++.h> using namespace std; #include <atcoder/modint> using namespace atcoder; using mint = modint998244353; //using mint = modint1000000007; #pragma region template using ll = long long; template <class T> using V = vector<T>; #define rep(i,n) for(int i=0;i<n;++i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((int)(x).size()) #define pb push_back #define eb emplace_back #define fi first #define se second #ifdef LOCAL #define debug(var) do{std::cerr << "\033[1;36m" << #var << ": \033[0m";view(var);std::cerr << std::endl;}while(0) template<typename T> void view(T e){std::cerr << e;} template<typename T, typename K> void view(pair<T, K> e){std::cerr << "("; view(e.fi); std::cerr << ", "; view(e.se); std::cerr << ")";} template<typename T> void view(const set<T> &st){ std::cerr << "\n";for(const auto& e : st){view(e); std::cerr << " ";}} template<typename T> void view(const multiset<T> &st){ std::cerr << "\n";for(const auto& e : st){view(e); std::cerr << " ";}} template<typename T, typename K> void view(const map<T, K> &mp){ std::cerr << "\n";for(const auto& [k, v]: mp){std::cerr << "("; view(k); std::cerr << ", "; view(v); std::cerr << ") ";}} template<typename T> void view(const unordered_map<int, T> &mp){ std::cerr << "\n";for(const auto& [k, v]: mp){std::cerr << "("; view(k); std::cerr << ", "; view(v); std::cerr << ") ";}} template<typename T> void view(const std::vector<T>& v){std::cerr << "\n";for(const auto& e : v){ view(e); std::cerr << " "; }} template<typename T> void view(const std::vector<std::vector<T> >& vv){std::cerr << "\n";int cnt = 0;for(const auto& v : vv){cerr << cnt << "th : "; view(v); cnt++; std::cerr << std::endl;}} #else #define debug(var) 0 #endif ll power(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a;} a = a * a; p >>= 1;} return ret;} ll modpow(ll a, ll p, ll mod){ll ret = 1; while(p){assert(a < mod); if(p & 1){ret = ret * a % mod;} a = a * a % mod; p >>= 1;} return ret;} ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0; while (b) {ll t = a / b ;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;} template<class T, class K>bool chmax(T &a, const K b) { if (a<b) { a=b; return 1; } return 0; } template<class T, class K>bool chmin(T &a, const K b) { if (b<a) { a=b; return 1; } return 0; } #pragma endregion int dx[]={1,0,-1,0}; int dy[]={0,1,0,-1}; const int inf = 1001001001; const ll INF = 1001001001001001001ll; //const double pi = acos(-1); const ll mod = 998244353; //const ll mod = 1000000007; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); //cout << fixed << setprecision(20); int n; cin >> n; V<int> t(n + 1), a(n + 1), b(n + 1); for(int i = 2; i <= n; i++) cin >> t[i] >> a[i] >> b[i]; V<mint> dp(51); V<bool> done(51); auto dfs = [&](auto&& self, int id, mint x)->mint{ if(id == 0) return 1; else if(id == 1) return x; else if(done[id]) return dp[id]; done[id] = 1; if(t[id] == 1) return dp[id] = self(self, a[id], x) + self(self, b[id], x); else if(t[id] == 2) return dp[id] = a[id] * self(self, b[id], x); else return dp[id] = self(self, a[id], x) * self(self, b[id], x); }; int q; cin >> q; while(q--){ dp.assign(51, 0); done.assign(51, 0); int x; cin >> x; cout << dfs(dfs, n, x).val() << '\n'; } }