QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#131641 | #2674. Vision program | somethingnew# | 0 | 31ms | 5592kb | C++20 | 7.1kb | 2023-07-27 19:43:39 | 2024-07-04 00:59:16 |
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_and(a);
}
mt19937 rnd;
vector<int> toans;
vector<vector<int>> druz;
void genshin(int H, int W, int prob) {
vector<int> op1, op2;
vector<int> typp(H * W, 2);
for (int i = 0; i < H * W; ++i) {
if (rnd() % prob == 0) {
typp[i] = 1;
op1.push_back(i);
}
}
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) {
for (int j1 = 0; j1 < W; ++j1) {
if (abs(i - i1) + abs(j - j1) == K) {
druz[i * W + j].push_back(i1 * W + j1);
}
}
}
}
}
toans.clear();
cn1 = 0;cn2 = 0;
while (cn2 + toans.size() < 960000 and cn1 < 9990) {
genshin(H, W, K * 2);
}
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
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 5ms
memory: 4204kb
input:
c2675211-ade0-44b0-8c15-741dd835f3d2 1 3 1 -1
output:
b17553fd-ba5a-4140-836c-491f938c515b OK 9992 0 1 2 0 1 0 0 2 3 4 0 1 0 0 1 2 0 2 6 7 0 1 2 0 1 0 0 2 9 10 0 1 2 0 1 0 0 2 12 13 0 1 2 0 1 0 0 2 15 16 0 1 2 0 1 0 0 2 18 19 0 1 0 0 1 2 0 2 21 22 0 1 2 0 1 0 0 2 24 25 0 1 0 0 1 2 0 2 27 28 0 1 2 0 1 0 0 2 30 31 0 1 2 0 1 0 0 2 33 34 0 1 0 0 1 2 0 2 36...
result:
ok
Test #2:
score: 0
Wrong Answer
time: 4ms
memory: 4128kb
input:
c2675211-ade0-44b0-8c15-741dd835f3d2 1 3 2 -1
output:
b17553fd-ba5a-4140-836c-491f938c515b OK 9992 0 1 0 0 1 1 0 2 3 4 0 1 1 0 2 0 2 0 2 6 7 0 1 0 0 1 1 0 2 9 10 0 2 0 2 0 1 1 0 2 12 13 0 1 2 0 1 1 0 2 15 16 0 1 1 0 2 0 2 0 2 18 19 0 1 0 0 1 1 0 2 21 22 0 1 1 0 2 0 2 0 2 24 25 0 1 0 0 1 1 0 2 27 28 0 1 1 0 2 0 2 0 2 30 31 0 1 2 0 1 1 0 2 33 34 0 1 2 0 ...
result:
wrong answer on inputs (0, 0), (0, 1), expected 0, but computed 1
Subtask #2:
score: 0
Wrong Answer
Test #19:
score: 0
Wrong Answer
time: 5ms
memory: 4340kb
input:
c2675211-ade0-44b0-8c15-741dd835f3d2 1 9 3 -1
output:
b17553fd-ba5a-4140-836c-491f938c515b OK 9992 0 2 1 8 0 5 0 2 3 6 7 0 2 9 10 0 3 3 4 6 0 3 2 5 8 0 2 12 13 0 1 6 0 7 0 1 2 4 5 7 8 0 2 15 16 0 2 3 7 0 4 1 2 5 8 0 2 18 19 0 2 0 8 0 5 1 2 4 6 7 0 2 21 22 0 2 0 1 0 5 2 5 6 7 8 0 2 24 25 0 3 1 2 4 0 4 0 3 6 8 0 2 27 28 0 1 7 0 7 0 1 2 3 5 6 8 0 2 30 31 ...
result:
wrong answer on inputs (0, 0), (0, 1), expected 0, but computed 1
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: 31ms
memory: 5592kb
input:
c2675211-ade0-44b0-8c15-741dd835f3d2 1 199 1 -1
output:
b17553fd-ba5a-4140-836c-491f938c515b OK 9992 0 104 0 1 2 4 8 12 13 15 17 19 24 25 26 28 30 33 34 39 40 41 43 45 47 49 50 52 53 54 55 56 58 59 62 63 64 65 66 67 71 75 77 78 79 80 83 84 86 88 91 92 95 96 98 99 102 104 105 107 110 111 113 114 115 116 118 119 120 128 131 132 133 134 136 137 138 140 141 ...
result:
wrong answer on inputs (0, 0), (0, 2), expected 0, but computed 1
Subtask #6:
score: 0
Wrong Answer
Test #70:
score: 0
Wrong Answer
time: 5ms
memory: 4284kb
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 0 1 0 0 1 3 0 2 4 5 0 1 0 0 1 3 0 2 7 8 0 1 3 0 1 0 0 2 10 11 0 1 3 0 1 0 0 2 13 14 0 1 3 0 1 0 0 2 16 17 0 1 2 0 1 1 0 2 19 20 0 1 0 0 1 3 0 2 22 23 0 1 3 0 1 0 0 2 25 26 0 1 3 0 1 0 0 2 28 29 0 1 1 0 1 2 0 2 31 32 0 1 0 0 1 3 0 2 34 35 0 1 1 0 1 2 0 2 3...
result:
wrong answer on inputs (0, 0), (1, 1), expected 0, but computed 1
Subtask #7:
score: 0
Time Limit Exceeded
Test #101:
score: 0
Time Limit Exceeded
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 140 0 20093 0 1 2 4 8 12 13 15 17 19 24 25 26 28 30 33 34 39 40 41 43 45 47 49 50 52 53 54 55 56 58 59 62 63 64 65 66 67 71 75 77 78 79 80 83 84 86 88 91 92 95 96 98 99 102 104 105 107 110 111 113 114 115 116 118 119 120 128 131 132 133 134 136 137 138 140 141...
result:
Subtask #8:
score: 0
Skipped
Dependency #1:
0%