Task: | Abandoned warehouse |
Sender: | esya_rae |
Submission time: | 2024-09-09 17:28:02 +0300 |
Language: | Python3 (CPython3) |
Status: | READY |
Result: | TIME LIMIT EXCEEDED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.02 s | details |
#2 | ACCEPTED | 0.02 s | details |
#3 | ACCEPTED | 0.02 s | details |
#4 | ACCEPTED | 0.02 s | details |
#5 | ACCEPTED | 0.02 s | details |
#6 | TIME LIMIT EXCEEDED | -- | details |
#7 | TIME LIMIT EXCEEDED | -- | details |
#8 | TIME LIMIT EXCEEDED | -- | details |
#9 | TIME LIMIT EXCEEDED | -- | details |
#10 | TIME LIMIT EXCEEDED | -- | details |
#11 | ACCEPTED | 0.03 s | details |
#12 | ACCEPTED | 0.03 s | details |
#13 | TIME LIMIT EXCEEDED | -- | details |
#14 | ACCEPTED | 0.02 s | details |
#15 | ACCEPTED | 0.02 s | details |
#16 | TIME LIMIT EXCEEDED | -- | 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: TIME LIMIT EXCEEDED
input |
---|
1000 1000 ##.###..######.#########.###.#... |
correct output |
---|
NO |
user output |
---|
(empty) |
Test 7
Verdict: TIME LIMIT EXCEEDED
input |
---|
1000 1000 ####.#.###....#.......##.##.#.... |
correct output |
---|
YES 626 LLLDDRDDDDLDLDDLLLLLDDDDLLDLDL... |
user output |
---|
(empty) |
Test 8
Verdict: TIME LIMIT EXCEEDED
input |
---|
1000 1000 ....#.##......#....#......#...... |
correct output |
---|
YES 364 LULULLULLLULLLLLUULLLLUUULLLLL... |
user output |
---|
(empty) |
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) |