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 <cstdio>
int arr[18];
int cnt[18];
int n, m;
int op[405], x[405], y[405], z[450];
int f[18];
void backtrack(int pos){
if(pos == n){
int arr2[18];
for(int i=0; i<n; i++){
arr2[i] = arr[i];
}
for(int i=0; i<m; i++){
if(op[i] == 0){
arr2[x[i]] = arr2[y[i]] + arr2[z[i]];
}
if(op[i] == 1){
arr2[x[i]] = arr2[y[i]] ^ arr2[z[i]];
}
if(op[i] == 2){
arr2[x[i]] = arr2[y[i]] + z[i];
}
if(op[i] == 3){
arr2[x[i]] = arr2[y[i]] ^ z[i];
}
arr2[x[i]] &= 3;
}
for(int i=0; i<n; i++){
cnt[i] += arr2[i];
cnt[i] %= 4;
}
return;
}
for(int i=0; i<4; i++){
if(i == f[pos]) continue;
arr[pos] = i;
backtrack(pos+1);
arr[pos] = 0;
}
}
int main(){
scanf("%d %d",&n,&m);
for(int i=0; i<n; i++){
scanf("%d",&f[i]);
}
for(int i=0; i<m; i++){
scanf("%d %d %d %d",&op[i],&x[i],&y[i],&z[i]);
}
backtrack(0);
for(int i=0; i<n; i++){
printf("%d ",cnt[i]);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |