Submission #627341

#TimeUsernameProblemLanguageResultExecution timeMemory
627341iomoon191쿼터너리 컴퓨터 (kriii3_Z)C++17
31 / 126
4016 ms1996 KiB
#include <bits/stdc++.h> #define all(a) (a).begin(), (a).end() #define sz(a) (int) (a.size()) #define pb push_back #define fi first #define se second #define For(i, a, b) for(int i = a; i <= b; i++) #define roF(i, a, b) for(int i = a; i >= b; i--) using namespace std; using ll = long long; // #define int ll using vi = vector<int>; using pi = pair<int, int>; const int N = 100005; const int inf = 0x3f3f3f3f; mt19937 rng(random_device {}()); int rand(int a){ return rng() % a; } namespace Rec{ template<class Fun> class y_combinator_result{ Fun fun_; public: template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)){} template<class ...Args> decltype(auto) operator()(Args &&...args){ return fun_(std::ref(*this), std::forward<Args>(args)...); } }; template<class Fun> decltype(auto) y_combinator(Fun &&fun){ return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); } } int n, m; vi a1(20), a2(20), cnt(20), f(20), type(N), x(N), y(N), z(N); void rmain(){ cin >> n >> m; For(i, 0, n - 1) cin >> f[i]; For(i, 0, m - 1) cin >> type[i] >> x[i] >> y[i] >> z[i]; function<void(int)> _solve = [&](int pos){ if(pos == n){ For(i, 0, n - 1) a2[i] = a1[i]; For(i, 0, m - 1){ if(type[i] == 0) a2[x[i]] = a2[y[i]] + a2[z[i]]; if(type[i] == 1) a2[x[i]] = a2[y[i]] ^ a2[z[i]]; if(type[i] == 2) a2[x[i]] = a2[y[i]] + z[i]; if(type[i] == 3) a2[x[i]] = a2[y[i]] ^ z[i]; a2[x[i]] &= 3; } For(i, 0, n - 1) cnt[i] = (cnt[i] + a2[i]) % 4; return; } For(i, 0, 3){ if(i == f[pos]) continue; a1[pos] = i; _solve(pos + 1); a1[pos] = 0; } }; _solve(0); cnt.resize(n); for(auto &i : cnt) cout << i << " "; } signed main(int argc, char *argv[]){ iostream::sync_with_stdio(0); int T = 1; while(T--) rmain(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...