Task: | Abandoned warehouse |
Sender: | Mojojijo |
Submission time: | 2024-09-10 21:13:11 +0300 |
Language: | Python3 (PyPy3) |
Status: | READY |
Result: | TIME LIMIT EXCEEDED |
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.10 s | details |
#7 | ACCEPTED | 0.51 s | details |
#8 | ACCEPTED | 0.41 s | details |
#9 | TIME LIMIT EXCEEDED | -- | details |
#10 | TIME LIMIT EXCEEDED | -- | details |
#11 | ACCEPTED | 0.09 s | details |
#12 | ACCEPTED | 0.07 s | details |
#13 | TIME LIMIT EXCEEDED | -- | details |
#14 | ACCEPTED | 0.05 s | details |
#15 | ACCEPTED | 0.05 s | details |
#16 | TIME LIMIT EXCEEDED | -- | details |
Code
from collections import deque def bfs(grid, n, m, start, end): directions = {'L': (0, -1), 'R': (0, 1), 'U': (-1, 0), 'D': (1, 0)} reverse_dir = {v: k for k, v in directions.items()} queue = deque([start]) visited = [[False] * m for _ in range(n)] visited[start[0]][start[1]] = True parent = {} while queue: r, c = queue.popleft() if (r, c) == end: path = [] while (r, c) != start: pr, pc = parent[(r, c)] direction = reverse_dir[(r - pr, c - pc)] path.append(direction) r, c = pr, pc return len(path), ''.join(path[::-1]) for _, (dr, dc) in directions.items(): nr, nc = r + dr, c + dc if 0 <= nr < n and 0 <= nc < m and not visited[nr][nc]: if grid[nr][nc] == '.' or grid[nr][nc] == 'B': visited[nr][nc] = True parent[(nr, nc)] = (r, c) queue.append((nr, nc)) return None n, m = map(int, input().split()) grid = [input().strip() for _ in range(n)] start = None end = None for i in range(n): for j in range(m): if grid[i][j] == 'A': start = (i, j) elif grid[i][j] == 'B': end = (i, j) result = bfs(grid, n, m, start, end) if result: length, path = result print("YES") print(length) print(path) 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: 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: 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 LULULLULLLULLLLLUULLLLUUULLLLL... Truncated |
Test 9
Verdict: TIME LIMIT EXCEEDED
input |
---|
1000 1000 .................#......#........ |
correct output |
---|
YES 1003 LLLLLLLLLLLLLLLLLLLLLLLLLDLLLL... |
user output |
---|
(empty) |
Test 10
Verdict: TIME LIMIT EXCEEDED
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: TIME LIMIT EXCEEDED
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: TIME LIMIT EXCEEDED
input |
---|
1000 1000 A................................ |
correct output |
---|
YES 1998 RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR... |
user output |
---|
(empty) |