QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#131649#2674. Vision programsomethingnew#0 18ms4592kbC++207.2kb2023-07-27 19:51:362024-07-04 00:59:39

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 00:59:39]
  • 评测
  • 测评结果:0
  • 用时:18ms
  • 内存:4592kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-27 19:51:36]
  • 提交

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) {
    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;
    int ctry = 0;
    while (cn2 + toans.size() < 960000 and cn1 < 9990 and ctry < 10000) {
        genshin(H, W, K);
        ctry++;
    }
    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: 1ms
memory: 3656kb

input:

c2675211-ade0-44b0-8c15-741dd835f3d2
1 3 1
-1

output:

b17553fd-ba5a-4140-836c-491f938c515b
WA
Instruction with no inputs

result:

wrong answer WA in grader: Instruction with no inputs

Subtask #2:

score: 0
Wrong Answer

Test #19:

score: 11
Accepted
time: 5ms
memory: 4076kb

input:

c2675211-ade0-44b0-8c15-741dd835f3d2
1 9 3
-1

output:

b17553fd-ba5a-4140-836c-491f938c515b
OK
9992
1 2 1 8
1 5 0 2 3 6 7
0 2 9 10
1 4 3 4 6 7
1 3 2 5 8
0 2 12 13
1 1 6
1 7 0 1 2 4 5 7 8
0 2 15 16
1 4 0 3 4 7
1 3 2 5 8
0 2 18 19
1 3 0 1 8
1 3 2 6 7
0 2 21 22
1 3 0 1 7
1 4 2 5 6 8
0 2 24 25
1 5 1 2 4 5 6
1 1 0
0 2 27 28
1 2 0 2
1 5 1 4 6 7 8
0 2 30 31
1 ...

result:

ok 

Test #20:

score: 11
Accepted
time: 0ms
memory: 4112kb

input:

c2675211-ade0-44b0-8c15-741dd835f3d2
9 1 5
-1

output:

b17553fd-ba5a-4140-836c-491f938c515b
OK
9992
1 2 3 7
1 5 0 1 4 5 6
0 2 9 10
1 4 1 2 3 6
1 3 0 4 5
0 2 12 13
1 2 1 8
1 5 0 2 4 5 7
0 2 15 16
1 2 6 7
1 5 0 3 4 5 8
0 2 18 19
1 2 1 7
1 5 0 3 4 5 8
0 2 21 22
1 2 2 7
1 7 0 1 3 4 5 6 8
0 2 24 25
1 1 5
1 7 1 2 3 4 6 7 8
0 2 27 28
1 2 2 7
1 7 0 1 3 4 5 6 8
...

result:

ok 

Test #21:

score: 11
Accepted
time: 18ms
memory: 4316kb

input:

c2675211-ade0-44b0-8c15-741dd835f3d2
10 5 2
-1

output:

b17553fd-ba5a-4140-836c-491f938c515b
OK
9992
1 24 0 1 2 4 8 12 13 15 17 19 24 25 26 28 30 33 34 39 40 41 43 45 47 49
1 1 48
0 2 50 51
1 23 1 3 4 13 14 15 19 21 22 23 24 27 31 32 33 35 36 37 38 41 42 44 45
1 4 0 6 10 49
0 2 53 54
1 24 0 1 10 11 13 16 17 18 19 24 25 26 27 29 30 31 36 38 41 42 45 47 48...

result:

ok 

Test #22:

score: 11
Accepted
time: 8ms
memory: 4592kb

input:

c2675211-ade0-44b0-8c15-741dd835f3d2
5 10 12
-1

output:

b17553fd-ba5a-4140-836c-491f938c515b
OK
9992
1 7 12 15 30 39 40 43 45
1 39 1 2 3 4 5 6 7 10 11 13 14 16 17 18 20 21 22 23 24 25 26 27 28 29 31 32 33 34 35 36 37 38 41 42 44 46 47 48 49
0 2 50 51
1 4 14 17 38 49
1 44 0 2 3 4 5 6 7 8 9 11 12 13 15 16 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 ...

result:

ok 

Test #23:

score: 0
Wrong Answer
time: 6ms
memory: 3652kb

input:

c2675211-ade0-44b0-8c15-741dd835f3d2
10 10 1
-1

output:

b17553fd-ba5a-4140-836c-491f938c515b
WA
Instruction with no inputs

result:

wrong answer WA in grader: Instruction with no inputs

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: 16ms
memory: 3780kb

input:

c2675211-ade0-44b0-8c15-741dd835f3d2
1 199 1
-1

output:

b17553fd-ba5a-4140-836c-491f938c515b
WA
Instruction with no inputs

result:

wrong answer WA in grader: Instruction with no inputs

Subtask #6:

score: 0
Wrong Answer

Test #70:

score: 0
Wrong Answer
time: 1ms
memory: 3656kb

input:

c2675211-ade0-44b0-8c15-741dd835f3d2
2 2 1
3 128
128 129
128 130
128 131

output:

b17553fd-ba5a-4140-836c-491f938c515b
WA
Instruction with no inputs

result:

wrong answer WA in grader: Instruction with no inputs

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:

Unauthorized output

result:


Subtask #8:

score: 0
Skipped

Dependency #1:

0%