Task: | Abandoned warehouse |
Sender: | esya_rae |
Submission time: | 2024-09-09 17:37:59 +0300 |
Language: | Python3 (PyPy3) |
Status: | READY |
Result: | ACCEPTED |
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.47 s | details |
#7 | ACCEPTED | 0.89 s | details |
#8 | ACCEPTED | 0.91 s | details |
#9 | ACCEPTED | 0.95 s | details |
#10 | ACCEPTED | 0.98 s | details |
#11 | ACCEPTED | 0.10 s | details |
#12 | ACCEPTED | 0.09 s | details |
#13 | ACCEPTED | 0.85 s | details |
#14 | ACCEPTED | 0.05 s | details |
#15 | ACCEPTED | 0.05 s | details |
#16 | ACCEPTED | 0.93 s | 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: 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 RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR... Truncated |