QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#131704#2674. Vision programsomethingnew#Compile Error//C++207.5kb2023-07-27 22:01:242024-07-04 01:00:15

Judging History

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

  • [2024-07-04 01:00:15]
  • 评测
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-27 22:01:24]
  • 提交

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.pop_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) {
                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;
    genshin(H, W, K + 5, 0);

    while (cn2 + toans.size() < 960000 and cn1 < 9990 and ctry * H * W < 5e5) {
        genshin(H, W, K + 5);
        ctry++;
    }
    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

answer.code: In function ‘void genshin(int, int, int, int)’:
answer.code:64:21: error: no matching function for call to ‘std::vector<int>::pop_back(int)’
   64 |         op1.pop_back(0);
      |         ~~~~~~~~~~~~^~~
In file included from /usr/include/c++/13/vector:66,
                 from answer.code:5:
/usr/include/c++/13/bits/stl_vector.h:1319:7: note: candidate: ‘constexpr void std::vector<_Tp, _Alloc>::pop_back() [with _Tp = int; _Alloc = std::allocator<int>]’
 1319 |       pop_back() _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1319:7: note:   candidate expects 0 arguments, 1 provided