QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#807578#9564. Hey, Have You Seen My Kangaroo?alexz1205Compile Error//C++142.9kb2024-12-10 07:44:452024-12-10 07:44:46

Judging History

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

  • [2024-12-10 07:44:46]
  • 评测
  • [2024-12-10 07:44:45]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int NM = 2e5, K = 200;

typedef long long int lint;
typedef complex<int> vect;

int n, m, k;

template<typename T, size_t SIZE>
struct Multarr{
	size_t N, M;
	T data[SIZE];

	Multarr(){
		N = n;
		M = m;
	}

	Multarr(int N, int M){
		this->N = N;
		this->M = M;
		memset(data, 0, sizeof(data));
	}

	T* operator[](size_t i){
		return &data[i*M];
	}

	T& operator[](vect cur){
		return data[cur.real()*M + cur.imag()];
	}
};

char buff[K+5];
Multarr<char, 2*NM> grid;
Multarr<int, NM> req;
Multarr<vect, NM> nex;

void setUpArrs(){
	grid.N = n;
	grid.M = m;
	memset(grid.data, 0, sizeof(grid.data));

	req.N = n;
	req.M = m;
	memset(req.data, 0, sizeof(req.data));

	nex.N = n;
	nex.M = m;
}

map<char, vect> dir = {{'U', vect(-1, 0)}, {'D', vect(1, 0)}, {'L', vect(0, -1)}, {'R', vect(0, 1)}};

vect move(vect cur, vect mov){
	vect v = cur+mov;
	v = vect(min(max(v.real(), 0), n-1), min(max(v.imag(), 0), m-1));
	if (grid[v] != '0'){
		return v;
	}
	return cur;
}

int ans[NM+1];

int main(){
	scanf("%d %d %d", &n, &m, &k);
	scanf("%s", buff);
//	cout << n << " " << m << " " << k << endl;
	setUpArrs();
	for (int x = 0; x < n; x ++){
		scanf("%s", grid[x]);
	}
//	cout << "HI" << endl;
	size_t sz = 0;
	for (int x = 0; x < n; x ++){
		for (int y = 0; y < m; y ++){
			if (grid[x][y] != '0'){
				sz ++;

				vect cur(x, y);
//				cout << cur << " ";
				for (int z = 0; z < k; z ++){
					cur = move(cur, dir[buff[z]]);
				}
//				cout << cur << endl;
				nex[x][y] = cur;
				req[cur] ++;
			}
		}
	}
//	cout << "HELLO" << endl;
	vector<vect> rem;
	for (int x = 0; x < n; x ++){
		for (int y = 0; y < m; y ++){
			if (grid[x][y] != '0'){
				vect cur(x, y);
				if (!req[cur]) rem.push_back(cur);
			}
		}
	}

	memset(ans, -1, sizeof(ans));
	memset(ans+sz, 0, sizeof(ans) - sz*sizeof(int));

//	cout << "HELLO" << endl;

	int mov = 0;
	size_t i = sz-1;
	while (!rem.empty()){
//		for (vect x: rem){
//			cout << x << " ";
//		}
//		cout << endl;
		vector<vect> nexRem;
		set<vect, decltype([](vect a, vect b){return (array<int,2>){a.real(), a.imag()} < (array<int, 2>){b.real(), b.imag()};})> spect;
		for (vect cur: rem){
			spect.insert(cur);
			spect.insert(nex[cur]);
			req[nex[cur]] --;
			if (!req[nex[cur]]) nexRem.push_back(nex[cur]);
		}
		for (int x = 0; x < k; x ++){
//			for (vect cur: spect){
//				cout << cur << " ";
//			}
//			cout << endl;
			decltype(spect) newSpect;
			for (vect cur: spect){
				newSpect.insert(move(cur, dir[buff[x]]));
			}
			sz -= spect.size() - newSpect.size();
			swap(spect, newSpect);
			while (i >= sz){
				ans[i--] = mov*k + x + 1;
			}
		}
		swap(nexRem, rem);
		mov ++;
	}

//	cout << "HELLO" << endl;

	for (int x = 1; x <= n*m; x ++){
		printf("%d\n", ans[x]);
	}
//	cout << "HELLO" << endl;
}

Details

answer.code: In function ‘int main()’:
answer.code:117:36: error: lambda-expression in unevaluated context only available with ‘-std=c++20’ or ‘-std=gnu++20’
  117 |                 set<vect, decltype([](vect a, vect b){return (array<int,2>){a.real(), a.imag()} < (array<int, 2>){b.real(), b.imag()};})> spect;
      |                                    ^
answer.code:117:137: error: template argument 2 is invalid
  117 |                 set<vect, decltype([](vect a, vect b){return (array<int,2>){a.real(), a.imag()} < (array<int, 2>){b.real(), b.imag()};})> spect;
      |                                                                                                                                         ^
answer.code:119:31: error: request for member ‘insert’ in ‘spect’, which is of non-class type ‘int’
  119 |                         spect.insert(cur);
      |                               ^~~~~~
answer.code:120:31: error: request for member ‘insert’ in ‘spect’, which is of non-class type ‘int’
  120 |                         spect.insert(nex[cur]);
      |                               ^~~~~~
answer.code:130:40: error: ‘begin’ was not declared in this scope; did you mean ‘std::begin’?
  130 |                         for (vect cur: spect){
      |                                        ^~~~~
      |                                        std::begin
In file included from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:166,
                 from answer.code:1:
/usr/include/c++/13/valarray:1232:5: note: ‘std::begin’ declared here
 1232 |     begin(const valarray<_Tp>& __va) noexcept
      |     ^~~~~
answer.code:130:40: error: ‘end’ was not declared in this scope; did you mean ‘std::end’?
  130 |                         for (vect cur: spect){
      |                                        ^~~~~
      |                                        std::end
/usr/include/c++/13/valarray:1259:5: note: ‘std::end’ declared here
 1259 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
answer.code:131:42: error: request for member ‘insert’ in ‘newSpect’, which is of non-class type ‘int’
  131 |                                 newSpect.insert(move(cur, dir[buff[x]]));
      |                                          ^~~~~~
answer.code:133:37: error: request for member ‘size’ in ‘spect’, which is of non-class type ‘int’
  133 |                         sz -= spect.size() - newSpect.size();
      |                                     ^~~~
answer.code:133:55: error: request for member ‘size’ in ‘newSpect’, which is of non-class type ‘int’
  133 |                         sz -= spect.size() - newSpect.size();
      |                                                       ^~~~
answer.code:68:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   68 |         scanf("%d %d %d", &n, &m, &k);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
answer.code:69:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   69 |         scanf("%s", buff);
      |         ~~~~~^~~~~~~~~~~~
answer.code:73:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   73 |                 scanf("%s", grid[x]);
      |                 ~~~~~^~~~~~~~~~~~~~~