Task: | Abandoned warehouse |
Sender: | Meriem |
Submission time: | 2024-09-09 17:43:17 +0300 |
Language: | Python3 (PyPy3) |
Status: | READY |
Result: | RUNTIME ERROR |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.05 s | details |
#2 | ACCEPTED | 0.05 s | details |
#3 | ACCEPTED | 0.05 s | details |
#4 | ACCEPTED | 0.05 s | details |
#5 | ACCEPTED | 0.05 s | details |
#6 | ACCEPTED | 0.13 s | details |
#7 | ACCEPTED | 0.30 s | details |
#8 | ACCEPTED | 0.26 s | details |
#9 | ACCEPTED | 0.60 s | details |
#10 | ACCEPTED | 0.65 s | details |
#11 | RUNTIME ERROR | 0.13 s | details |
#12 | RUNTIME ERROR | 0.11 s | details |
#13 | RUNTIME ERROR | 0.60 s | details |
#14 | ACCEPTED | 0.05 s | details |
#15 | ACCEPTED | 0.05 s | details |
#16 | RUNTIME ERROR | 0.78 s | details |
Code
from collections import deque import sys sys.setrecursionlimit(700) def bfs(x, y, output): moves[x][y] = "X" possible_moves = [(1, 0, "D"), (0, -1, "L"), (-1, 0, "U"), (0, 1, "R")] end = False q = deque([(x, y)]) while q: x, y = q.popleft() if graph[x][y] == "B": end = True break visited[x][y] = True for dx, dy, move in possible_moves: new_x, new_y = x + dx, y + dy if ( 0 <= new_x < n and 0 <= new_y < m and graph[new_x][new_y] != "#" and not visited[new_x][new_y] ): visited[new_x][new_y] = True moves[new_x][new_y] = move q.append((new_x, new_y)) if end: back_path(x, y, output) return True else: return False def task3(n, m, graph): output = [] for i in range(n): for j in range(m): if graph[i][j] == "A": start = (i, j) elif graph[i][j] == "B": dest = (i, j) if bfs(start[0], start[1], output): print("YES") print(len(output)) output = reversed(output) print("".join(output)) else: print("NO") def back_path(x, y, output): if moves[x][y] != "X": move = moves[x][y] output.append(move) if move == "U": back_path(x + 1, y, output) elif move == "D": back_path(x - 1, y, output) elif move == "L": back_path(x, y + 1, output) elif move == "R": back_path(x, y - 1, output) if __name__ == "__main__": n, m = map(int, input().split()) graph = [input().strip() for i in range(n)] visited = [[False] * m for i in range(n)] moves = [] moves = [[""] * m for i in range(n)] task3(n, m, graph)
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 DLL |
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 LLLDDRDDDDDDLLDDLLDDDLDDLLLDDL... Truncated |
Test 8
Verdict: ACCEPTED
input |
---|
1000 1000 ....#.##......#....#......#...... |
correct output |
---|
YES 364 LULULLULLLULLLLLUULLLLUUULLLLL... |
user output |
---|
YES 364 LULULLULLLULLLLLUULLLLUUULLLLL... Truncated |
Test 9
Verdict: ACCEPTED
input |
---|
1000 1000 .................#......#........ |
correct output |
---|
YES 1003 LLLLLLLLLLLLLLLLLLLLLLLLLDLLLL... |
user output |
---|
YES 1003 DDDDDDDDDDDDDDDDDLDDDDDDDDDDDD... Truncated |
Test 10
Verdict: ACCEPTED
input |
---|
1000 1000 ................................. |
correct output |
---|
YES 947 LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL... |
user output |
---|
YES 947 LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL... Truncated |
Test 11
Verdict: RUNTIME ERROR
input |
---|
1000 3 A#B .#. .#. .#. ... |
correct output |
---|
YES 2000 DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD... |
user output |
---|
(empty) |
Error:
Traceback (most recent call last): File "input/code.py", line 75, in <module> task3(...
Test 12
Verdict: RUNTIME ERROR
input |
---|
3 1000 A................................ |
correct output |
---|
YES 2000 RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR... |
user output |
---|
(empty) |
Error:
Traceback (most recent call last): File "input/code.py", line 75, in <module> task3(...
Test 13
Verdict: RUNTIME ERROR
input |
---|
999 999 A#...#...#...#...#...#...#...#... |
correct output |
---|
YES 499998 DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD... |
user output |
---|
(empty) |
Error:
Traceback (most recent call last): File "input/code.py", line 75, in <module> task3(...
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: RUNTIME ERROR
input |
---|
1000 1000 A................................ |
correct output |
---|
YES 1998 RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR... |
user output |
---|
(empty) |
Error:
Traceback (most recent call last): File "input/code.py", line 75, in <module> task3(...