#include "vision.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
using i64 = long long;
using d64 = long double;
using pi = pair<int, int>;
using pli = pair<i64, i64>;
using ti = tuple<int, int, int>;
using tli = tuple<i64, i64, i64>;
#define iterall(cont) cont.begin(), cont.end()
#define prec(n) setprecision(n) << fixed
void construct_network(int H, int W, int K) {
auto valid = [H, W](int x, int y) {
return 0 <= x && x < H && 0 <= y && y < W;
};
auto getNum = [W](int x, int y) { return x * W + y; };
int c = H * W;
vector<int> idx1;
for (int s = 0; s < H + W - 1; s++) {
vector<int> tmp;
for (int x = 0; x < H; x++) {
int y = s - x;
if (valid(x, y)) tmp.emplace_back(getNum(x, y));
}
add_or(tmp);
idx1.emplace_back(c++);
}
vector<int> idx2;
for (int s = W - 1; s >= -(H - 1); --s) {
vector<int> tmp;
for (int x = 0; x < H; x++) {
int y = x + s;
if (valid(x, y)) tmp.emplace_back(getNum(x, y));
}
add_or(tmp);
idx2.emplace_back(c++);
}
if (K == 1) {
vector<int> idx4;
for (int i = 0; i < idx1.size() - K; i++) {
add_and({idx1[i], idx1[i+K]});
idx4.emplace_back(c++);
}
vector<int> idx5;
for (int i = 0; i < idx2.size() - K; i++) {
add_and({idx2[i], idx2[i+K]});
idx5.emplace_back(c++);
}
add_or(idx4);
add_or(idx5);
add_and({c, c + 1});
return;
}
// K - 1 연속 (False여야 함)
vector<int> idx3_1;
for (int i = 0; i <= idx1.size() - K + 1; i++) {
vector<int> tmp;
copy(idx1.begin() + i, idx1.begin() + i + K - 1, back_inserter(tmp));
add_or(tmp);
add_xor(tmp);
add_xor({c, c + 1});
idx3_1.emplace_back(c + 2);
c += 3;
}
vector<int> idx3_2;
for (int i = 0; i <= idx2.size() - K + 1; i++) {
vector<int> tmp;
copy(idx2.begin() + i, idx2.begin() + i + K - 1, back_inserter(tmp));
add_or(tmp);
add_xor(tmp);
add_xor({c, c + 1});
idx3_2.emplace_back(c + 2);
c += 3;
}
// K 연속 (True여야 함)
vector<int> idx4;
for (int i = 0; i < idx1.size() - K; i++) {
add_and({idx1[i], idx1[i+K]});
idx4.emplace_back(c++);
}
vector<int> idx5;
for (int i = 0; i < idx2.size() - K; i++) {
add_and({idx2[i], idx2[i+K]});
idx5.emplace_back(c++);
}
add_or(idx3_1); // c
add_or(idx3_2); // c+1
add_or(idx4); // c+2
add_or(idx5); // c+3
add_and({c, c + 3}); // c+4
add_and({c + 1, c + 2}); // c+5
add_and({c + 2, c + 3}); // c+6
add_or({c + 4, c + 5, c + 6});
}
Compilation message
vision.cpp: In function 'void construct_network(int, int, int)':
vision.cpp:53:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int i = 0; i < idx1.size() - K; i++) {
| ~~^~~~~~~~~~~~~~~~~
vision.cpp:58:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for (int i = 0; i < idx2.size() - K; i++) {
| ~~^~~~~~~~~~~~~~~~~
vision.cpp:70:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for (int i = 0; i <= idx1.size() - K + 1; i++) {
| ~~^~~~~~~~~~~~~~~~~~~~~~
vision.cpp:81:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | for (int i = 0; i <= idx2.size() - K + 1; i++) {
| ~~^~~~~~~~~~~~~~~~~~~~~~
vision.cpp:93:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | for (int i = 0; i < idx1.size() - K; i++) {
| ~~^~~~~~~~~~~~~~~~~
vision.cpp:98:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
98 | for (int i = 0; i < idx2.size() - K; i++) {
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Incorrect |
1 ms |
256 KB |
on inputs (0, 1), (1, 0), expected 1, but computed 0 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Incorrect |
1 ms |
256 KB |
on inputs (0, 1), (1, 0), expected 1, but computed 0 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Incorrect |
1 ms |
256 KB |
on inputs (0, 1), (1, 0), expected 1, but computed 0 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Incorrect |
1 ms |
256 KB |
on inputs (0, 1), (1, 0), expected 1, but computed 0 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
9 ms |
768 KB |
Output is correct |
3 |
Correct |
6 ms |
768 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
7 ms |
640 KB |
Output is correct |
11 |
Correct |
6 ms |
768 KB |
Output is correct |
12 |
Correct |
6 ms |
768 KB |
Output is correct |
13 |
Correct |
4 ms |
640 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
640 KB |
Output is correct |
17 |
Correct |
8 ms |
768 KB |
Output is correct |
18 |
Correct |
6 ms |
768 KB |
Output is correct |
19 |
Correct |
4 ms |
640 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Incorrect |
1 ms |
416 KB |
on inputs (0, 0), (1, 1), expected 1, but computed 0 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1280 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
768 KB |
Output is correct |
8 |
Correct |
7 ms |
768 KB |
Output is correct |
9 |
Correct |
12 ms |
1280 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Incorrect |
1 ms |
256 KB |
on inputs (0, 1), (1, 0), expected 1, but computed 0 |
7 |
Halted |
0 ms |
0 KB |
- |