#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();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
3 ms |
340 KB |
Output is correct |
15 |
Correct |
180 ms |
212 KB |
Output is correct |
16 |
Correct |
180 ms |
340 KB |
Output is correct |
17 |
Correct |
1550 ms |
340 KB |
Output is correct |
18 |
Correct |
1375 ms |
324 KB |
Output is correct |
19 |
Correct |
1568 ms |
340 KB |
Output is correct |
20 |
Correct |
1733 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4065 ms |
340 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |