#include "vision.h"
#include <bits/stdc++.h>
using namespace std;
/*
int add_not(int N);
int add_and(vector<int> Ns);
int add_or(vector<int> Ns);
int add_xor(vector<int> Ns);
*/
vector<int> get_dis(int r, int c, vector<vector<int>> &grid, int k) {
int n = grid.size();
int m = grid[0].size();
vector<int> fin;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (abs(i - r) + abs(j - c) == k) fin.push_back(grid[i][j]);
}
}
return fin;
}
vector<int> get_row(int row, vector<vector<int>> &grid) {
int n = grid.size();
int m = grid[0].size();
if (row < 0 || row >= n) return {};
vector<int> currRow;
for (int j = 0; j < m; j++) {
currRow.push_back(grid[row][j]);
}
return currRow;
}
vector<int> get_col(int col, vector<vector<int>> &grid) {
int n = grid.size();
int m = grid[0].size();
if (col < 0 || col >= m) return {};
vector<int> currCol;
for (int j = 0; j < n; j++) {
currCol.push_back(grid[j][col]);
}
return currCol;
}
void construct_network(int H, int W, int K) {
int n = H;
int m = W;
int k = K;
vector<vector<int>> grid(n, vector<int>(m));
int curr = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
grid[i][j] = curr++;
}
}
int sameCol, sameRow, adjCol, adjRow;
// take the XOR of the ORs of all columns: true -> they are in the same column
// same for rows
vector<int> ors;
for (int col = 0; col < m; col++) {
vector<int> currCol = get_col(col, grid);
ors.push_back(add_or(currCol));
}
sameCol = add_xor(ors);
ors.clear();
for (int row = 0; row < n; row++) {
vector<int> currRow = get_row(row, grid);
ors.push_back(add_or(currRow));
}
sameRow = add_xor(ors);
// take the XOR of the ORs of all ADJACENT columns: true -> the are in adjacnt columns
ors.clear();
for (int col = 0; col <= m; col++) {
vector<int> a = get_col(col, grid);
vector<int> b = get_col(col-1, grid);
for (auto x: b) a.push_back(x);
ors.push_back(add_or(a));
}
adjCol = add_xor(ors);
ors.clear();
for (int row = 0; row <= n; row++) {
vector<int> a = get_row(row, grid);
vector<int> b = get_row(row-1, grid);
for (auto x: b) a.push_back(x);
ors.push_back(add_or(a));
}
adjRow = add_xor(ors);
add_or({add_and({adjCol, sameRow}), add_and({sameCol, adjRow})});
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |