Submission #309714

# Submission time Handle Problem Language Result Execution time Memory
309714 2020-10-04T11:19:45 Z lucaperju Vision Program (IOI19_vision) C++14
Compilation error
0 ms 0 KB
//#include "vision.h"
#include <bits/stdc++.h>
/*
#include <cstdio>
#include <cassert>
#include <string>
//#include "vision.h"

using namespace std;

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;
}

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 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);
}
*/
/// --------------------------------------------------------------------------------

using namespace std;
int mat[203][203];
vector<int>cols;
vector<int>lins;
vector<int>vc;
int diflin[203],difcol[203];
/*int add_not(int N)
{
    return 1;
}
int add_and(vector<int> Ns)
{
    return 1;
}
int add_or(vector<int> Ns)
{
    return 1;
}
int add_xor(vector<int> Ns)
{
    return 1;
}*/
int solvelin (int dif)
{
    int i;
    if(dif<=1)
    {
        vc.clear();
        for(i=0;i<lins.size();++i)
            vc.push_back(lins[i]);
        if(dif==0)
            return add_xor(vc);
        return add_not(add_xor(vc));
    }
    vector<int>aux1;
    for(i=0;i<lins.size();++i)
        aux1.push_back(i%dif+1);
    vector<int>aux2;
    for(int exp=0;exp<=8;++exp)
    {
        vc.clear();
        for(i=0;i<lins.size();++i)
            if(aux1[i]&(1<<exp))
                vc.push_back(lins[i]);
        if(vc.size()==0)
            break;
        aux2.push_back(add_xor(vc));
    }
    return add_not(add_or(aux2));
}
int solvecol (int dif)
{
    int i;
    if(dif<=1)
    {
        vc.clear();
        for(i=0;i<cols.size();++i)
            vc.push_back(cols[i]);
        if(dif==0)
            return add_xor(vc);
        return add_not(add_xor(vc));
    }
    vector<int>aux1;
    for(i=0;i<cols.size();++i)
        aux1.push_back(i%dif+1);
    vector<int>aux2;
    for(int exp=0;exp<=8;++exp)
    {
        vc.clear();
        for(i=0;i<cols.size();++i)
            if(aux1[i]&(1<<exp))
                vc.push_back(cols[i]);
        if(vc.size()==0)
            break;
        aux2.push_back(add_xor(vc));
    }
    return add_not(add_or(aux2));
}
void construct_network(int n, int m, int K) {
	/**
	std::vector<int> Ns;
	Ns = {0, 1};
	int a = add_and(Ns);
	Ns = {0, a};
	int b = add_or(Ns);
	Ns = {0, 1, b};
	int c = add_xor(Ns);
	add_not(c);
    */
    int i,j,k=0;
    for(i=1;i<=n;++i)
        for(j=1;j<=m;++j)
            mat[i][j]=k++;
    for(i=1;i<=n;++i)
    {
        vc.clear();
        for(j=1;j<=m;++j)
            vc.push_back(mat[i][j]);
        lins.push_back(add_or(vc));
    }
    for(j=1;j<=m;++j)
    {
        vc.clear();
        for(i=1;i<=n;++i)
            vc.push_back(mat[i][j]);
        cols.push_back(add_or(vc));
    }
    for(i=0;i<n;++i)
        diflin[i]=solvelin(i);
    for(j=0;j<m;++j)
        difcol[j]=solvecol(j);
    vector<int>aux;
    for(i=0;i<=min(n-1,K);++i)
    {
        if(K-i>=m)
            continue;
        vc.clear();
        j=K-i;
        for(k=i+1;k<n;++k)
            vc.push_back(diflin[k]);
        for(k=j+1;k<m;++k)
            vc.push_back(difcol[k]);
        if(vc.size())
        {
            int pzc=add_not(add_or(vc));
            vc.clear();
            vc.push_back(pzc);
            vc.push_back(diflin[i]);
            vc.push_back(difcol[j]);
            aux.push_back(add_and(vc));
        }
        else
        {
            vc.push_back(diflin[i]);
            vc.push_back(difcol[j]);
            aux.push_back(add_and(vc));
        }
    }
    add_or(aux);
}
/*

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);
}
*/

Compilation message

vision.cpp: In function 'int solvelin(int)':
vision.cpp:152:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  152 |         for(i=0;i<lins.size();++i)
      |                 ~^~~~~~~~~~~~
vision.cpp:155:20: error: 'add_xor' was not declared in this scope
  155 |             return add_xor(vc);
      |                    ^~~~~~~
vision.cpp:156:24: error: 'add_xor' was not declared in this scope
  156 |         return add_not(add_xor(vc));
      |                        ^~~~~~~
vision.cpp:156:16: error: 'add_not' was not declared in this scope
  156 |         return add_not(add_xor(vc));
      |                ^~~~~~~
vision.cpp:159:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  159 |     for(i=0;i<lins.size();++i)
      |             ~^~~~~~~~~~~~
vision.cpp:165:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  165 |         for(i=0;i<lins.size();++i)
      |                 ~^~~~~~~~~~~~
vision.cpp:170:24: error: 'add_xor' was not declared in this scope
  170 |         aux2.push_back(add_xor(vc));
      |                        ^~~~~~~
vision.cpp:172:20: error: 'add_or' was not declared in this scope
  172 |     return add_not(add_or(aux2));
      |                    ^~~~~~
vision.cpp:172:12: error: 'add_not' was not declared in this scope
  172 |     return add_not(add_or(aux2));
      |            ^~~~~~~
vision.cpp: In function 'int solvecol(int)':
vision.cpp:180:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  180 |         for(i=0;i<cols.size();++i)
      |                 ~^~~~~~~~~~~~
vision.cpp:183:20: error: 'add_xor' was not declared in this scope
  183 |             return add_xor(vc);
      |                    ^~~~~~~
vision.cpp:184:24: error: 'add_xor' was not declared in this scope
  184 |         return add_not(add_xor(vc));
      |                        ^~~~~~~
vision.cpp:184:16: error: 'add_not' was not declared in this scope
  184 |         return add_not(add_xor(vc));
      |                ^~~~~~~
vision.cpp:187:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  187 |     for(i=0;i<cols.size();++i)
      |             ~^~~~~~~~~~~~
vision.cpp:193:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  193 |         for(i=0;i<cols.size();++i)
      |                 ~^~~~~~~~~~~~
vision.cpp:198:24: error: 'add_xor' was not declared in this scope
  198 |         aux2.push_back(add_xor(vc));
      |                        ^~~~~~~
vision.cpp:200:20: error: 'add_or' was not declared in this scope
  200 |     return add_not(add_or(aux2));
      |                    ^~~~~~
vision.cpp:200:12: error: 'add_not' was not declared in this scope
  200 |     return add_not(add_or(aux2));
      |            ^~~~~~~
vision.cpp: In function 'void construct_network(int, int, int)':
vision.cpp:222:24: error: 'add_or' was not declared in this scope
  222 |         lins.push_back(add_or(vc));
      |                        ^~~~~~
vision.cpp:229:24: error: 'add_or' was not declared in this scope
  229 |         cols.push_back(add_or(vc));
      |                        ^~~~~~
vision.cpp:248:29: error: 'add_or' was not declared in this scope
  248 |             int pzc=add_not(add_or(vc));
      |                             ^~~~~~
vision.cpp:248:21: error: 'add_not' was not declared in this scope
  248 |             int pzc=add_not(add_or(vc));
      |                     ^~~~~~~
vision.cpp:253:27: error: 'add_and' was not declared in this scope
  253 |             aux.push_back(add_and(vc));
      |                           ^~~~~~~
vision.cpp:259:27: error: 'add_and' was not declared in this scope
  259 |             aux.push_back(add_and(vc));
      |                           ^~~~~~~
vision.cpp:262:5: error: 'add_or' was not declared in this scope
  262 |     add_or(aux);
      |     ^~~~~~