CSES - Aalto Competitive Programming 2024 - wk2 - Mon - Results
Submission details
Task:Abandoned warehouse
Sender:Niilo
Submission time:2024-09-10 21:02:27 +0300
Language:C++ (C++17)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.01 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.07 sdetails
#7ACCEPTED0.08 sdetails
#8ACCEPTED0.07 sdetails
#9ACCEPTED0.08 sdetails
#10ACCEPTED0.08 sdetails
#11ACCEPTED0.01 sdetails
#12ACCEPTED0.00 sdetails
#13ACCEPTED0.08 sdetails
#14ACCEPTED0.00 sdetails
#15ACCEPTED0.00 sdetails
#16ACCEPTED0.08 sdetails

Code

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

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

int main() {
	cin >> n >> m;
  for (int i = 0; i < n+2; ++i) C[i][0] = C[i][m+1] = 1e9;
  for (int i = 0; i < m+2; ++i) C[0][i] = C[n+1][i] = 1e9;
	int x = 0, y = 0, x0 = 0, y0 = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			char c;
			cin >> c;
			if (c == '#') C[i][j] = 1e9;
			else 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();
    const int DIR[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};
    for (auto [x2,y2] : DIR) {
      if (C[y+y2][x+x2] == 0) {
        C[y+y2][x+x2] = w;
			  Q.push({x+x2,y+y2,w});
      }
    }
	}
  if (Q.empty()) {
    cout << "NO\n";
    return 0;
  }
	int w = C[y0][x0];
	string P;
	swap(x,x0);
	swap(y,y0);
	while (--w > 0) {
		if (C[y][x-1] == w) {
			P += 'R';
			--x;
		}
		else if (C[y-1][x] == w) {
			P += 'D';
			--y;
		}
		else if (C[y][x+1] == w) {
			P += 'L';
			++x;
		}
		else if (C[y+1][x] == w) {
			P += 'U';
			++y;
		} else {
      assert(0);
    }
	}
	reverse(P.begin(), P.end());
	cout << "YES\n" << P.size() << '\n' << P;
}

Test details

Test 1

Verdict: ACCEPTED

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

correct output
NO

user output
NO

Test 2

Verdict: ACCEPTED

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

correct output
NO

user output
NO

Test 3

Verdict: ACCEPTED

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

correct output
YES
3
LLD

user output
YES
3
LLD

Test 4

Verdict: ACCEPTED

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

correct output
YES
1
R

user output
YES
1
R

Test 5

Verdict: ACCEPTED

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

correct output
YES
3
RDD

user output
YES
3
DDR

Test 6

Verdict: ACCEPTED

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

correct output
NO

user output
NO

Test 7

Verdict: ACCEPTED

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

correct output
YES
626
LLLDDRDDDDLDLDDLLLLLDDDDLLDLDL...

user output
YES
626
LLLDDRDDDDLDLDDLLLLLDDDDLLDLDL...
Truncated

Test 8

Verdict: ACCEPTED

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

correct output
YES
364
LULULLULLLULLLLLUULLLLUUULLLLL...

user output
YES
364
UUUUUULUUUUUUUUUUULLLUUUULLUUU...
Truncated

Test 9

Verdict: ACCEPTED

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

correct output
YES
1003
LLLLLLLLLLLLLLLLLLLLLLLLLDLLLL...

user output
YES
1003
LLLLLLLLLLLLLLLLLLLLLLLLLDLLLL...
Truncated

Test 10

Verdict: ACCEPTED

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

correct output
YES
947
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL...

user output
YES
947
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUU...
Truncated

Test 11

Verdict: ACCEPTED

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

correct output
YES
2000
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD...

user output
YES
2000
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD...
Truncated

Test 12

Verdict: ACCEPTED

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

correct output
YES
2000
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
YES
2000
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...
Truncated

Test 13

Verdict: ACCEPTED

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

correct output
YES
499998
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD...

user output
YES
499998
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD...
Truncated

Test 14

Verdict: ACCEPTED

input
1 3
A.B

correct output
YES
2
RR

user output
YES
2
RR

Test 15

Verdict: ACCEPTED

input
2 2
##
AB

correct output
YES
1
R

user output
YES
1
R

Test 16

Verdict: ACCEPTED

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

correct output
YES
1998
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
YES
1998
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD...
Truncated