CSES - Aalto Competitive Programming 2024 - wk2 - Mon - Results
Submission details
Task:Abandoned warehouse
Sender:Niilo
Submission time:2024-09-09 17:13:41 +0300
Language:C++17
Status:READY
Result:
Test results
testverdicttime
#1--details
#2--details
#3--details
#4--details
#5--details
#6--details
#7--details
#8--details
#9--details
#10--details
#11--details
#12--details
#13--details
#14--details
#15--details
#16--details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:56:24: warning: 'y0' may be used uninitialized in this function [-Wmaybe-uninitialized]
   56 |         while (x != x0 || y != y0) {
      |                ~~~~~~~~^~~~~~~~~~
input/code.cpp:56:24: warning: 'x0' may be used uninitialized in this function [-Wmaybe-uninitialized]
input/code.cpp:56:24: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
input/code.cpp:56:24: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]

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,w});
		}
		if (y > 0 && C[y-1][x] == 0) {
			C[y-1][x] = w;
			Q.push({y-1,x,w});
		}
		if (x < m-1 && C[y][x+1] == 0) {
			C[y][x+1] = w;
			Q.push({y,x+1,w});
		}
		if (y < n-1 && C[y+1][x] == 0) {
			C[y+1][x] = w;
			Q.push({y+1,x,w});
		}
	}
	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;
}

Test details

Test 1

Verdict:

input
10 10
##.A######
#.##.##.##
#####..###
.#########
...

correct output
NO

user output
(empty)

Test 2

Verdict:

input
10 10
B#..##.#..
#....A##..
#.....#..#
.#......#.
...

correct output
NO

user output
(empty)

Test 3

Verdict:

input
10 10
...#..A.#.
....B...##
...#......
..........
...

correct output
YES
3
LLD

user output
(empty)

Test 4

Verdict:

input
10 10
.#........
..........
..........
........#.
...

correct output
YES
1
R

user output
(empty)

Test 5

Verdict:

input
10 10
..........
..........
..........
..........
...

correct output
YES
3
RDD

user output
(empty)

Test 6

Verdict:

input
1000 1000
##.###..######.#########.###.#...

correct output
NO

user output
(empty)

Test 7

Verdict:

input
1000 1000
####.#.###....#.......##.##.#....

correct output
YES
626
LLLDDRDDDDLDLDDLLLLLDDDDLLDLDL...

user output
(empty)

Test 8

Verdict:

input
1000 1000
....#.##......#....#......#......

correct output
YES
364
LULULLULLLULLLLLUULLLLUUULLLLL...

user output
(empty)

Test 9

Verdict:

input
1000 1000
.................#......#........

correct output
YES
1003
LLLLLLLLLLLLLLLLLLLLLLLLLDLLLL...

user output
(empty)

Test 10

Verdict:

input
1000 1000
.................................

correct output
YES
947
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL...

user output
(empty)

Test 11

Verdict:

input
1000 3
A#B
.#.
.#.
.#.
...

correct output
YES
2000
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD...

user output
(empty)

Test 12

Verdict:

input
3 1000
A................................

correct output
YES
2000
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 13

Verdict:

input
999 999
A#...#...#...#...#...#...#...#...

correct output
YES
499998
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD...

user output
(empty)

Test 14

Verdict:

input
1 3
A.B

correct output
YES
2
RR

user output
(empty)

Test 15

Verdict:

input
2 2
##
AB

correct output
YES
1
R

user output
(empty)

Test 16

Verdict:

input
1000 1000
A................................

correct output
YES
1998
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)