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 <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <set>
using namespace std;
int main()
{
int N, M;
cin >> N >> M;
vector<int> f(N);
for (int i=0; i<N; i++) cin >> f[i];
vector<int> cmd(M), x(M), y(M), z(M);
for (int i=0; i<M; i++)
cin >> cmd[i] >> x[i] >> y[i] >> z[i];
vector<int> t(N);
for (int bit=0; bit<(1<<(2*N)); bit ++) {
int ok = 1;
for (int i=0; i<N; i++)
if (((bit>>(2*i))&3) == f[i]) {
ok = 0;
break;
}
if (!ok) continue;
vector<int> reg(N);
for (int i=0; i<N; i++)
reg[i] = (bit>>(2*i))&3;
for (int i=0; i<M; i++) {
if (cmd[i] == 0) reg[x[i]] = (reg[y[i]] + reg[z[i]]) & 3;
else if (cmd[i] == 1) reg[x[i]] = reg[y[i]] ^ reg[z[i]];
else if (cmd[i] == 2) reg[x[i]] = (reg[y[i]] + z[i]) & 3;
else reg[x[i]] = reg[y[i]] ^ z[i];
}
for (int i=0; i<N; i++) t[i] = (t[i] + reg[i]) & 3;
}
for (int i=0; i<N; i++) cout << t[i] << " ";
cout << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |