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

Code

import sys

sys.setrecursionlimit(10 ** 6)

height, width = map(int, input().split())

grid = []

for h in range(height):
    row = list(input())
    grid.append(row)

A_pos = (0, 0)
B_pos = (0, 0)

for h, row in enumerate(grid):
    for w, el in enumerate(row):
        if el == "A":
            A_pos = (h, w)
        if el == "B":
            B_pos = (h, w)


best_sol = ""


def dfs(h, w, directions: str, vis: list[list[bool]]):
    global best_sol
    if h >= height or w >= width or h < 0 or w < 0 or grid[h][w] == "#" or vis[h][w]:
        return

    visit = vis.copy()
    visit[h][w] = True

    if grid[h][w] == "B":
        if (not best_sol) or len(best_sol) > len(directions):
            best_sol = directions
        return

    dfs(h - 1, w, directions + "U", visit.copy())
    dfs(h, w + 1, directions + "R", visit.copy())
    dfs(h + 1, w, directions + "D", visit.copy())
    dfs(h, w - 1, directions + "L", visit.copy())


visited = [[False for _ in range(width)] for _ in range(height)]
dfs(A_pos[0], A_pos[1], "", visited)

if best_sol:
    print("YES")
    print(len(best_sol))
    print(best_sol)
else:
    print("NO")

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:

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

correct output
YES
3
LLD

user output
YES
23
RDDRRDDDDLUUULDLUUULULD

Test 4

Verdict:

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

correct output
YES
1
R

user output
YES
23
UUUUUUUURRDDDDDLDDRDDLU

Test 5

Verdict:

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

correct output
YES
3
RDD

user output
YES
59
UUUUURRRRRRDDDDDDDDDLUUUUUUUUL...

Test 6

Verdict: ACCEPTED

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

correct output
NO

user output
NO

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)