Submission #752731

# Submission time Handle Problem Language Result Execution time Memory
752731 2023-06-03T14:07:37 Z the_programmer_of_python Painting Walls (APIO20_paint) C++11
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

#define _us using
#define _tp template
#define _tn typename
#define _ot cout <<
#define _er cerr <<
#define _in cin >>
#define _p << ' ' <<
#define _nl '\n'
#define _el << _nl
#define _rg(i, s, e) for (auto i = s; i < e; ++i)
#define _up(i, e) _rg(i, 0, e)
#define _ce constexpr
#define _cs const
#define _st static
#define _il inline
_us ll = long long;
_tp<_tn _t> _us vec = vector<_t>;
_tp<_tn _t> _us dbl = pair<_t, _t>;
_us sz = size_t;
_us u32 = uint32_t;
#define _mp make_pair
#define _mt make_tuple
#define _f first
#define _s second

struct Vm {
	_st _ce sz max_mem = 100*1000;
	_st _ce int max_threads = 50*1000;
	_st _ce int max_alphabet = 100*1000;
	sz mem_size;
	int threads;
	int symbol_max;
	//int mem[max_mem];
	int *_cs mem;
	bool active[max_mem];
	//int symbols_count[50*1000];
	int *_cs symbols_count;
	//int *symbols[50*1000];
	int *_cs*_cs symbols;

	inline bool is_valid(int thread, int ptr) {
		assert(0 <= thread && thread < this->threads);
		assert(0 <= ptr && ptr < this->mem_size);

		_cs int symbol = this->mem[ptr];
		_cs int n_valid = this->symbols_count[thread];
		_cs int *_cs valid = this->symbols[thread];

		_up(i, n_valid) {
			if (symbol == valid[i]) return true;
		}
		return false;
	}
	bool advance(int x, int y) {
		assert(0 <= x && x < this->threads);
		assert(0 <= y && y <= this->mem_size - this->threads);
		bool res = false;

		_rg(l, 0, this->threads) {
			_cs int thread = (x+l)%this->threads;
			if (this->is_valid(thread, y+l)) {
				res = true;
				active[y+l] = true;
			}
		}

		return res;
	}
};

int minimumInstructions(int N, int M, int K, int *C, int *A, int **B) {
	Vm vm{.mem_size = (sz)N, .symbol_max = M, .mem = C, .symbols_count = A, .symbols = B};
	memset(vm.active, 0, sizeof(vm.active));

	return -1;
}

/*|------------------------------------------------------------------------|*\
|*|  Spec:                                                                 |*|
|*|    Start with the following parameters:                                |*|
|*|      N -- mem size                                                     |*|
|*|      M -- threads                                                      |*|
|*|      K -- symbol count                                                 |*|
|*|      C -- mem values                                                   |*|
|*|      A -- # of valid symbols per thread                                |*|
|*|      B -- valid symbols of each thread                                 |*|
|*|    Return: Minimum # of instructions to activate entire memory, or -1  |*|
|*|    INSR(x, y) ==                                                       |*|
|*|        x -- 0..<M                                                      |*|
|*|        y -- 0..(N-M)                                                   |*|
|*|      For all l in 0..<M                                                |*|
|*|      Use thread ((x + l) % M)                                          |*|
|*|      If C[y+l] is a valid symbol, activate it                          |*|
\*|------------------------------------------------------------------------|*/

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from paint.cpp:1:
paint.cpp: In member function 'bool Vm::is_valid(int, int)':
paint.cpp:47:26: warning: comparison of integer expressions of different signedness: 'int' and 'sz' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   assert(0 <= ptr && ptr < this->mem_size);
      |                      ~~~~^~~~~~~~~~~~~~~~
paint.cpp: In member function 'bool Vm::advance(int, int)':
paint.cpp:60:22: warning: comparison of integer expressions of different signedness: 'int' and 'sz' {aka 'long unsigned int'} [-Wsign-compare]
   60 |   assert(0 <= y && y <= this->mem_size - this->threads);
      |                    ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/cc9fP1v3.o: in function `main':
grader.cpp:(.text.startup+0x38f): undefined reference to `minimumInstructions(int, int, int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >)'
collect2: error: ld returned 1 exit status