This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using ll = long long;
#define int ll
using namespace std;
#define sz(x) (int)(x).size()
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, l, r) for(int i = l; i >= r; i--)
#define fi first
#define se second
#define mod 998244353
#define db(x) cerr << __LINE__ << " " << #x << " " << x << "\n"
using vi = vector<int>;
using pi = pair<int, int>;
const ll N = 405;
const ll inf = 1e18;
int n, m;
vi a1(20), a2(20), cnt(20), f(20), type(N), x(N), y(N), z(N);
void solve(){
cin >> n >> m;
foru(i, 0, n - 1) cin >> f[i];
foru(i, 0, m - 1){
cin >> type[i] >> x[i] >> y[i] >> z[i];
}
function<void(int)> _solve = [&](int pos){
if(pos == n){
foru(i, 0, n - 1) a2[i] = a1[i];
foru(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;
}
foru(i, 0, n - 1){
cnt[i] = (cnt[i] + a2[i]) % 4;
}
return;
}
foru(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(){
ios_base::sync_with_stdio(0); cin.tie(0);
int t = 1; // cin >> t;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |