CSES - Aalto Competitive Programming 2024 - wk2 - Mon - Results
Submission details
Task:Abandoned warehouse
Sender:Niilo
Submission time:2024-09-09 17:12:32 +0300
Language:C++17
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:37:31: error: no matching function for call to 'std::queue<std::tuple<int, int, int> >::push(<brace-enclosed initializer list>)'
   37 |                         Q.push({y,x-1});
      |                         ~~~~~~^~~~~~~~~
In file included from /usr/include/c++/11/queue:64,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:86,
                 from input/code.cpp:1:
/usr/include/c++/11/bits/stl_queue.h:265:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::tuple<int, int, int>; _Sequence = std::deque<std::tuple<int, int, int>, std::allocator<std::tuple<int, int, int> > >; std::queue<_Tp, _Sequence>::value_type = std::tuple<int, int, int>]'
  265 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/11/bits/stl_queue.h:265:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const...

Code

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

int C[1001][1001];
int n, m;

int main() {
	cin >> n >> m;
	int x, y, x0, y0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			char c;
			cin >> c;
			C[i][j] = 1e9;
			if (c == 'A') {
				y = i;
				x = j;
			} else if (c == 'B') {
				y0 = i;
				x0 = j;
			}
		}
	}
	C[y][x] = 1;
	queue<tuple<int,int,int>> Q;
	Q.push({x,y,1});
	while (!Q.empty()) {
		auto [x,y,w] = Q.front();
		if (x == x0 && y == y0) {
			break;
		}
		++w;
		Q.pop();
		if (x > 0 && C[y][x-1] == 0) {
			C[y][x-1] = w;
			Q.push({y,x-1});
		}
		if (y > 0 && C[y-1][x] == 0) {
			C[y-1][x] = w;
			Q.push({y-1,x});
		}
		if (x < m-1 && C[y][x+1] == 0) {
			C[y][x+1] = w;
			Q.push({y,x+1});
		}
		if (y < n-1 && C[y+1][x] == 0) {
			C[y+1][x] = w;
			Q.push({y+1,x});
		}
	}
	int w = C[y0][x0];
	string P;
	swap(x,x0);
	swap(y,y0);
	while (x != x0 || y != y0) {
		--w;
		if (x > 0 && C[y][x-1] == w) {
			P += 'R';
			--x;
		}
		if (y > 0 && C[y-1][x] == w) {
			P += 'D';
			--y;
		}
		if (x < m-1 && C[y][x+1] == w) {
			P += 'L';
			++x;
		}
		if (y < n-1 && C[y+1][x] == w) {
			P += 'U';
			++y;
		}
	}
	reverse(P.begin(), P.end());
	cout << P;
}