QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#131709 | #2674. Vision program | somethingnew# | 0 | 27ms | 6408kb | C++20 | 7.8kb | 2023-07-27 22:06:29 | 2024-07-04 01:00:21 |
Judging History
answer
// ↘ ⬇ ⬇ ⬇ ⬇ ⬇ ↙
// ➡ @roadfromroi ⬅
// ↗ ⬆ ⬆ ⬆ ⬆ ⬆ ↖
#include <iostream>
#include "vector"
#include "algorithm"
#include "numeric"
#include "climits"
#include "iomanip"
#include "bitset"
#include "cmath"
#include "map"
#include "deque"
#include "array"
#include "set"
#include "vision.h"
#include "random"
#define all(x) x.begin(), x.end()
using namespace std;
vector<int> getka(int n, int m) {
int res = 0;
vector<int> capa(n + m + 1);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
vector<int> beb(n + m + 1);
for (int i1 = i; i1 < n; ++i1) {
for (int j1 = j+1; j1 < m; ++j1) {
if (beb[abs(i-i1) + abs(j-j1)] == 0) {
capa[abs(i - i1) + abs(j - j1)]++;
beb[abs(i-i1) + abs(j-j1)] = 1;
}
}
}
}
}
return capa;
}
int cn1, cn2;
int my_and(vector<int> a) {
cn2 += a.size();
cn1 += 1;
return add_and(a);
}
int my_or(vector<int> &a) {
cn2 += a.size();
cn1 += 1;
return add_or(a);
}
mt19937 rnd;
vector<int> toans;
vector<vector<int>> druz;
void genshin(int H, int W, int prob, int beba = 0) {
vector<int> op1, op2;
vector<int> typp(H * W, 2);
if (beba == 0) {
for (int i = 0; i < H * W; ++i) {
if (rnd() % prob == 0) {
typp[i] = 1;
op1.push_back(i);
}
}
} else {
typp[0] = 1;
op1.push_back(0);
}
for (int i = 0; i < H * W; ++i) {
if (typp[i] == 1) {
for (auto j : druz[i]) {
if (typp[j] == 2)
typp[j] = 0;
}
}
}
//if (typp[0] + typp[1] == 3)
// cout << "DA\n";
for (int i = 0; i < H * W; ++i) {
if (typp[i] == 2) {
op2.push_back(i);
}
}
if (op1.empty() or op2.empty())
return;
int x = my_or(op1);
int y = my_or(op2);
int res = my_and(vector<int>{x, y});
toans.push_back(res);
}
void construct_network(int H, int W, int K) {
druz.assign(H * W, {});
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
for (int i1 = 0; i1 < H; ++i1) {
int j1 = j - (K - abs(i-i1));
if (0 <= j1 and j1 < W) {
if (abs(i - i1) + abs(j - j1) == K) {
druz[i * W + j].push_back(i1 * W + j1);
}
}
if (0 <= j1 and j1 < W) {
j1 = j + (K - abs(i - i1));
}
}
}
}
toans.clear();
cn1 = 0;cn2 = 0;
int ctry = 0;
if (min(H, W) == 1 or max(H, W) <= 30) {
while (cn2 + toans.size() < 960000 and cn1 < 9990 and ctry * H * W < 5e5) {
genshin(H, W, K + 5);
ctry++;
}
} else {
genshin(H, W, K + 5, 1);
}
if (toans.empty()) {
vector<int> t;
for (int i = 0; i < H * W; ++i) {
t.push_back(i);
}
int beba = my_or(t);
} else {
int beba = my_or(toans);
beba = add_not(beba);
}
//cout << toans.size() << ' ' << cn1 << ' ' << cn2 << endl;
}
//#define LOCAL
#ifdef LOCAL
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() {
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" : "%d"), memory_cells[i]);
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);
}
#endif
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 4412kb
input:
c2675211-ade0-44b0-8c15-741dd835f3d2 1 3 1 -1
output:
b17553fd-ba5a-4140-836c-491f938c515b OK 9992 1 1 1 1 1 2 0 2 3 4 1 1 2 1 1 0 0 2 6 7 1 2 0 1 1 1 2 0 2 9 10 1 1 0 1 2 1 2 0 2 12 13 1 1 0 1 2 1 2 0 2 15 16 1 1 0 1 2 1 2 0 2 18 19 1 1 1 1 1 2 0 2 21 22 1 1 1 1 1 2 0 2 24 25 1 1 0 1 2 1 2 0 2 27 28 1 1 2 1 1 0 0 2 30 31 1 2 0 1 1 1 2 0 2 33 34 1 1 1 ...
result:
wrong answer on inputs (0, 0), (0, 1), expected 1, but computed 0
Subtask #2:
score: 0
Wrong Answer
Test #19:
score: 0
Wrong Answer
time: 2ms
memory: 4240kb
input:
c2675211-ade0-44b0-8c15-741dd835f3d2 1 9 3 -1
output:
b17553fd-ba5a-4140-836c-491f938c515b OK 9992 1 1 6 1 7 0 1 2 4 5 7 8 0 2 9 10 1 1 8 1 7 0 1 2 3 4 6 7 0 2 12 13 1 2 3 7 1 5 1 2 5 6 8 0 2 15 16 1 2 0 1 1 7 2 3 4 5 6 7 8 0 2 18 19 1 2 5 7 1 5 0 1 3 6 8 0 2 21 22 1 1 7 1 7 0 1 2 3 5 6 8 0 2 24 25 1 2 5 8 1 6 0 1 3 4 6 7 0 2 27 28 1 2 0 8 1 6 1 2 3 4 ...
result:
wrong answer on inputs (0, 0), (0, 3), expected 1, but computed 0
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Wrong Answer
Test #48:
score: 0
Wrong Answer
time: 27ms
memory: 5964kb
input:
c2675211-ade0-44b0-8c15-741dd835f3d2 1 199 1 -1
output:
b17553fd-ba5a-4140-836c-491f938c515b OK 7541 1 38 1 8 12 13 15 24 30 34 39 40 41 43 45 53 54 55 64 65 67 88 99 104 105 107 113 115 116 119 120 133 140 143 145 153 154 169 182 194 1 133 2 3 4 5 6 9 10 16 17 18 19 20 21 22 25 26 27 28 31 32 35 36 37 46 47 48 49 50 51 56 57 58 59 60 61 62 68 69 70 71 7...
result:
wrong answer on inputs (0, 0), (0, 1), expected 1, but computed 0
Subtask #6:
score: 0
Wrong Answer
Test #70:
score: 0
Wrong Answer
time: 0ms
memory: 4128kb
input:
c2675211-ade0-44b0-8c15-741dd835f3d2 2 2 1 3 128 128 129 128 130 128 131
output:
b17553fd-ba5a-4140-836c-491f938c515b OK 9992 1 1 1 1 1 2 0 2 4 5 1 1 0 1 2 1 3 0 2 7 8 1 1 0 1 2 1 3 0 2 10 11 1 1 2 1 2 1 3 0 2 13 14 1 1 2 1 2 1 3 0 2 16 17 1 1 3 1 1 0 0 2 19 20 1 1 1 1 1 2 0 2 22 23 1 1 0 1 2 1 3 0 2 25 26 1 1 3 1 1 0 0 2 28 29 1 1 0 1 2 1 3 0 2 31 32 1 1 1 1 1 2 0 2 34 35 1 1 1...
result:
wrong answer on inputs (0, 0), (0, 1), expected 1, but computed 0
Subtask #7:
score: 0
Wrong Answer
Test #101:
score: 0
Wrong Answer
time: 14ms
memory: 6408kb
input:
c2675211-ade0-44b0-8c15-741dd835f3d2 200 200 1 100 524 24804 34853 20956 34628 18830 29184 28919 32573 11364 24911 2226 5624 3715 30838 2206 17143 21162 27531 20198 27242 5007 12724 27160 32586 3535 7307 17015 25466 626 13891 9132 26194 9198 33073 815 7328 6938 21395 9489 30995 10804 21530 14698 394...
output:
b17553fd-ba5a-4140-836c-491f938c515b OK 5 1 1 0 1 39998 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 8...
result:
wrong answer on inputs (126, 120), (176, 169), expected 0, but computed 1
Subtask #8:
score: 0
Skipped
Dependency #1:
0%