#include<bits/stdc++.h>
#include "vision.h"
using namespace std;
#define endl "\n"
typedef long long ll;
int h, w;
void calc(int n, vector<int>& dist, bool type){
vector<int> val(n);
for(int i = 0; i < n; i++){
vector<int> nws;
if(type == 0){
for(int j = 0; j < w; j++){
nws.push_back(i * w + j);
}
}else{
for(int j = 0; j < h; j++){
nws.push_back(j * w + i);
}
}
val[i] = add_or(nws);
//~ cout << "i " << i << " val " << val[i] << endl;
}
int curr = 1;
int mx = 0;
while(curr < n){
curr *= 2; mx++;
}
curr /= 2; mx--;
vector<int> prev(n);
//~ cout << "Type " << type << endl;
while(curr > 0){
vector<int> answers;
for(int start = 0; start < min(n, 2 * curr); start++){
if(start + curr - 1 >= n) break;
vector<int> nws;
vector<int> other;
vector<int> ind;
vector<bool> done(n, 0);
for(int i = start; i < n; i++){
if(((i-start) / curr) % 2 == 0) {nws.push_back(val[i]); ind.push_back(i); done[i] = 1;}
}
for(int i = 0; i < n; i++){
if(!done[i]) other.push_back(val[i]);
}
//~ cout << "start "<< start << " curr " << curr << " nws " << endl;
//~ for(int i = 0; i < (int)nws.size(); i++){
//~ cout << "ind "<< ind[i] << " val " << nws[i] << endl;
//~ }
//I want to check. 1) I have at least 1, the other has at least 1.
answers.push_back(add_or({add_not(add_or(nws)), add_and({add_or(nws), add_or(other)})}));
}
//It has the bit if the blacks aren't in the same array.
prev[curr] = add_and(answers);
//~ cout << "curr " << curr <<" dist " << prev[curr] << endl;
curr /= 2;
}
dist[0] = add_xor(val);
//~ cout << "dist0 " << dist[0] << endl;
for(int i = 1; i < n; i++){
vector<int> have;
vector<int> others = {dist[0]};
for(int j = 0; j <= mx; j++){
if((1 << j) & i) have.push_back(prev[(1 << j)]);
else others.push_back(prev[(1 << j)]);
}
dist[i] = add_and({add_and(have), add_not(add_or(others))});
//~ cout << "i " << i << " dist " << dist[i] << endl;
}
}
void construct_network(int H, int W, int K){
//Now, I want to get the value of each row.
h = H;
w = W;
vector<int> distr(H, -1);
vector<int> distc(W, -1);
calc(H, distr, 0);
calc(W, distc, 1);
vector<int> possibilities;
for(int i = 0; i < (int)distr.size() && i <= K; i++){
int j = K - i;
if(j >= (int)distc.size()) continue;
possibilities.push_back(add_and({distr[i], distc[j]}));
}
add_or(possibilities);
}
//~ static const int MAX_INSTRUCTIONS = 10000;
//~ static const int MAX_INPUTS = 1000000;
//~ static const int _AND = 0;
//~ static const int _OR = 1;
//~ static const int _XOR = 2;
//~ static const int _NOT = 3;
//~ static inline bool increasing(int a, int b, int c) {
//~ return a <= b && b <= c;
//~ }
//~ [[noreturn]] static inline void error(string message) {
//~ printf("%s\n", message.c_str());
//~ exit(0);
//~ }
//~ class InstructionNetwork {
//~ struct Instruction {
//~ int type;
//~ vector<int> input_indexes;
//~ inline Instruction(int _type, const vector<int>& _input_indexes):
//~ type(_type), input_indexes(_input_indexes) {
//~ }
//~ inline int apply(int a, int b) const {
//~ switch (type) {
//~ case _AND:
//~ return a & b;
//~ case _OR:
//~ return a | b;
//~ case _XOR:
//~ return a ^ b;
//~ default:
//~ return 0;
//~ }
//~ }
//~ inline int compute(const vector<int>& memory_cells) const {
//~ int r = memory_cells[input_indexes[0]];
//~ if (type == _NOT)
//~ return 1 - r;
//~ for (int j = 1; j < (int)input_indexes.size(); j++)
//~ r = apply(r, memory_cells[input_indexes[j]]);
//~ return r;
//~ }
//~ };
//~ int input_size;
//~ int total_inputs;
//~ vector<Instruction> instructions;
//~ public:
//~ inline void init(int _input_size) {
//~ this->input_size = _input_size;
//~ this->total_inputs = 0;
//~ this->instructions.clear();
//~ }
//~ inline int add_instruction(int type, const vector<int>& input_indexes) {
//~ if (input_indexes.size() == 0)
//~ error("Instruction with no inputs");
//~ if (instructions.size() + 1 > MAX_INSTRUCTIONS)
//~ error("Too many instructions");
//~ if (total_inputs + input_indexes.size() > MAX_INPUTS)
//~ error("Too many inputs");
//~ instructions.emplace_back(type, input_indexes);
//~ total_inputs += input_indexes.size();
//~ int new_index = input_size + (int)instructions.size() - 1;
//~ for (int input_index : input_indexes)
//~ if (!increasing(0, input_index, new_index-1))
//~ error("Invalid index");
//~ return new_index;
//~ }
//~ inline int compute(vector<int> &memory_cells) const {
//~ for (auto &instruction : instructions)
//~ memory_cells.push_back(instruction.compute(memory_cells));
//~ return memory_cells.back();
//~ }
//~ };
//~ static InstructionNetwork instructionNetwork;
//~ int main() {
//~ freopen("in.txt", "r", stdin);
//~ int H, W, K;
//~ assert(3 == scanf("%d%d%d", &H, &W, &K));
//~ FILE *log_file = fopen("log.txt","w");
//~ instructionNetwork.init(H * W);
//~ construct_network(H, W, K);
//~ while (true) {
//~ int rowA, colA, rowB, colB;
//~ assert(1 == scanf("%d", &rowA));
//~ if (rowA == -1)
//~ break;
//~ assert(3 == scanf("%d%d%d", &colA, &rowB, &colB));
//~ if ((!increasing(0, rowA, H-1)) ||
//~ (!increasing(0, colA, W-1)) ||
//~ (!increasing(0, rowB, H-1)) ||
//~ (!increasing(0, colB, W-1)) ||
//~ (rowA == rowB && colA == colB)) {
//~ printf("-1\n");
//~ fprintf(log_file, "-1\n");
//~ fflush(stdout);
//~ fflush(log_file);
//~ continue;
//~ }
//~ vector<int> memory_cells;
//~ for (int row = 0; row < H; row++)
//~ for (int col = 0; col < W; col++) {
//~ bool active = (row == rowA && col == colA) || (row == rowB && col == colB);
//~ memory_cells.push_back(active ? 1 : 0);
//~ }
//~ int computation_result = instructionNetwork.compute(memory_cells);
//~ printf("%d\n", computation_result);
//~ fflush(stdout);
//~ for(int i = 0; i < (int)memory_cells.size(); i++){
//~ fprintf(log_file, "i: %d\n", i);
//~ fprintf(log_file, (i ? " %d" : "%d"), memory_cells[i]);
//~ fprintf(log_file, "\n");
//~ }
//~ fprintf(log_file, "\n");
//~ fflush(log_file);
//~ }
//~ fclose(stdin);
//~ }
//~ int add_and(vector<int> Ns) {
//~ return instructionNetwork.add_instruction(_AND, Ns);
//~ }
//~ int add_or(vector<int> Ns) {
//~ return instructionNetwork.add_instruction(_OR, Ns);
//~ }
//~ int add_xor(vector<int> Ns) {
//~ return instructionNetwork.add_instruction(_XOR, Ns);
//~ }
//~ int add_not(int N) {
//~ vector<int> Ns = {N};
//~ return instructionNetwork.add_instruction(_NOT, Ns);
//~ }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Incorrect |
0 ms |
212 KB |
on inputs (0, 1), (0, 4), expected 1, but computed 0 |
20 |
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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Incorrect |
0 ms |
212 KB |
on inputs (0, 1), (0, 4), expected 1, but computed 0 |
20 |
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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Incorrect |
0 ms |
212 KB |
on inputs (0, 1), (0, 4), expected 1, but computed 0 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
1252 KB |
on inputs (0, 1), (0, 4), expected 0, but computed 1 |
2 |
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 |
4 ms |
724 KB |
Output is correct |
4 |
Correct |
4 ms |
664 KB |
Output is correct |
5 |
Correct |
4 ms |
724 KB |
Output is correct |
6 |
Correct |
4 ms |
672 KB |
Output is correct |
7 |
Correct |
4 ms |
724 KB |
Output is correct |
8 |
Correct |
6 ms |
980 KB |
Output is correct |
9 |
Correct |
6 ms |
980 KB |
Output is correct |
10 |
Correct |
9 ms |
980 KB |
Output is correct |
11 |
Correct |
6 ms |
1068 KB |
Output is correct |
12 |
Correct |
6 ms |
1052 KB |
Output is correct |
13 |
Correct |
10 ms |
1264 KB |
Output is correct |
14 |
Correct |
9 ms |
1196 KB |
Output is correct |
15 |
Correct |
10 ms |
1236 KB |
Output is correct |
16 |
Correct |
10 ms |
1224 KB |
Output is correct |
17 |
Correct |
11 ms |
1360 KB |
Output is correct |
18 |
Correct |
9 ms |
1228 KB |
Output is correct |
19 |
Correct |
9 ms |
1236 KB |
Output is correct |
20 |
Correct |
16 ms |
2220 KB |
Output is correct |
21 |
Correct |
16 ms |
2204 KB |
Output is correct |
22 |
Correct |
16 ms |
2212 KB |
Output is correct |
23 |
Correct |
16 ms |
2224 KB |
Output is correct |
24 |
Correct |
17 ms |
2152 KB |
Output is correct |
25 |
Correct |
16 ms |
2164 KB |
Output is correct |
26 |
Correct |
16 ms |
2128 KB |
Output is correct |
27 |
Correct |
26 ms |
3368 KB |
Output is correct |
28 |
Correct |
26 ms |
3424 KB |
Output is correct |
29 |
Correct |
26 ms |
3356 KB |
Output is correct |
30 |
Correct |
26 ms |
3452 KB |
Output is correct |
31 |
Correct |
26 ms |
3400 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
3364 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
4 ms |
596 KB |
Output is correct |
4 |
Correct |
6 ms |
1060 KB |
Output is correct |
5 |
Incorrect |
10 ms |
1236 KB |
on inputs (0, 1), (0, 4), expected 0, but computed 1 |
6 |
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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Incorrect |
0 ms |
212 KB |
on inputs (0, 1), (0, 4), expected 1, but computed 0 |
20 |
Halted |
0 ms |
0 KB |
- |