CSES - Aalto Competitive Programming 2024 - wk2 - Mon - Results
Submission details
Task:Abandoned warehouse
Sender:esya_rae
Submission time:2024-09-09 17:28:02 +0300
Language:Python3 (CPython3)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.02 sdetails
#2ACCEPTED0.02 sdetails
#3ACCEPTED0.02 sdetails
#4ACCEPTED0.02 sdetails
#5ACCEPTED0.02 sdetails
#6--details
#7--details
#8--details
#9--details
#10--details
#11ACCEPTED0.03 sdetails
#12ACCEPTED0.03 sdetails
#13--details
#14ACCEPTED0.02 sdetails
#15ACCEPTED0.02 sdetails
#16--details

Code

from collections import deque
n, m = map(int, input().split())
g = [[] for _ in range(n * m)]
used = [False for _ in range(n * m)]

start, finish = -1, -1

s_prev = ''
s = ''

for i in range(n):
    s_prev = s
    s = input()
    for j in range(m):
        if s[j] == "#":
            continue
        if i != 0 and s_prev[j] != '#':
            g[i * m + j].append((i - 1) * m + j)
            g[(i - 1) * m + j].append(i * m + j)
        if j != 0 and s[j - 1] != '#':
            g[i * m + j].append(i * m + j - 1)
        if j != m - 1 and s[j + 1] != '#':
            g[i * m + j].append(i * m + j + 1)

        if s[j] == 'A':
            start = i * m + j
        elif s[j] == 'B':
            finish = i * m + j

dist = [-1] * (n * m)
parent = [-1] * (n * m)

def bfs(v):
    global g, dist
    queue = deque([v])
    while queue:
        node = queue.popleft()
        for w in g[node]:
            if dist[w] == -1:
                parent[w] = node
                dist[w] = dist[node] + 1
                if w == finish:
                    break
                queue.append(w)



dist[start] = 0
bfs(start)

if dist[finish] == -1:
    print("NO")
else:
    print("YES")
    print(dist[finish])
    path = []
    path.append(finish)
    v = finish
    while parent[v] != start:
        path.append(parent[v])
        v = parent[v]
    path.append(start)
    path.reverse()
    for i in range(1, len(path)):
        if path[i] == path[i - 1] + 1:
            print('R', end='')
        elif path[i] == path[i - 1] - 1:
            print('L', end='')
        elif path[i] < path[i - 1]:
            print('U', end='')
        else:
            print('D', end='')

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
RDD

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: 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:

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

correct output
YES
499998
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD...

user output
(empty)

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:

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

correct output
YES
1998
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)