#include <bits/stdc++.h>
using namespace std;
#define pb push_back
int add_and(std::vector<int> Ns);
int add_or(std::vector<int> Ns);
int add_xor(std::vector<int> Ns);
int add_not(int N);
int transformCoords(int W, int i, int j) {
return i*W+j;
}
bool isValid(int H, int W, int i, int j) {
if (i < 0 || j < 0 || i >= H || j >= W) return false;
return true;
}
int idx;
int calc1(int H, int W) {
vector<int> Ns;
// int idx = H*W;
for (int i = 0; i < H; i++) {
vector<int> arr;
for (int j = 0; j < W; j++) arr.pb(i*W+j);
add_or(arr);
idx++;
}
int og = idx;
for (int i = 0; i < H-1; i++) {
add_and({og-H+i, og-H+i+1});
Ns.pb(idx);
idx++;
}
int consecOr1 = add_or(Ns);
idx++;
Ns = vector<int>();
for (int i = 0; i < W; i++) {
vector<int> arr;
for (int j = 0; j < H; j++) arr.pb(j*W+i);
add_or(arr);
add_xor(arr);
add_xor({idx, idx+1});
Ns.pb(idx+2);
idx+=3;
}
int consecXor1 = add_or(Ns);
// for (int i = 0; i < Ns.size(); i++) cout << Ns[i] << " ";
// cout << endl;
idx += 2;
return add_and({consecOr1, consecXor1});
}
int calc2(int H, int W) {
vector<int> Ns;
// int idx = H*W;
for (int i = 0; i < W; i++) {
vector<int> arr;
for (int j = 0; j < H; j++) arr.pb(j*W+i);
add_or(arr);
idx++;
}
int og = idx;
for (int i = 0; i < W-1; i++) {
add_and({og-W+i, og-W+i+1});
Ns.pb(idx);
idx++;
}
int consecOr1 = add_or(Ns);
idx++;
Ns = vector<int>();
for (int i = 0; i < H; i++) {
vector<int> arr;
for (int j = 0; j < W; j++) arr.pb(i*W+j);
add_or(arr);
add_xor(arr);
add_xor({idx, idx+1});
Ns.pb(idx+2);
idx+=3;
}
int consecXor1 = add_or(Ns);
idx += 2;
return add_and({consecOr1, consecXor1});
}
void construct_network(int H, int W, int K) {
if (H == 1 || W == 1) {
vector<int> Ns;
int idx = 0;
for (int x = 0; x < H; x++) {
for (int y = 0; y < W; y++) {
vector<int> arr;
for (int i = 0; i <= K; i++) {
if (isValid(H, W, i+x, K-i+y)) {
arr.pb(transformCoords(W, i+x, K-i+y));
}
if (isValid(H, W, x-i, K-i+y) && x-i != i+x) {
arr.pb(transformCoords(W, x-i, K-i+y));
}
}
if (arr.size()) {
add_or({transformCoords(W, x, y)});
add_or(arr);
idx += 2;
}
}
}
// for (int i = 0; i < Ns.size(); i++) {
// cout << Ns[i] << " x ";
// }
// cout << endl;
for (int i = 0; i < idx; i+=2) {
Ns.pb(add_and({H*W+i, H*W+i+1}));
}
add_or(Ns);
return;
}
idx = H*W;
add_or({calc1(H, W) , calc2(H, W)});
// cout << idx << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Incorrect |
0 ms |
212 KB |
on inputs (0, 0), (0, 1), expected 0, but computed 1 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Incorrect |
0 ms |
212 KB |
on inputs (0, 0), (0, 1), expected 0, but computed 1 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Incorrect |
0 ms |
212 KB |
on inputs (0, 0), (0, 1), expected 0, but computed 1 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Incorrect |
0 ms |
212 KB |
on inputs (0, 0), (0, 1), expected 0, but computed 1 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
296 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 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 |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
296 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
on inputs (0, 0), (0, 1), expected 0, but computed 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
2712 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
468 KB |
Output is correct |
4 |
Correct |
4 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
14 ms |
1464 KB |
Output is correct |
8 |
Correct |
12 ms |
1620 KB |
Output is correct |
9 |
Correct |
24 ms |
2644 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Incorrect |
0 ms |
212 KB |
on inputs (0, 0), (0, 1), expected 0, but computed 1 |
7 |
Halted |
0 ms |
0 KB |
- |