Task: | Abandoned warehouse |
Sender: | eyong002 |
Submission time: | 2024-09-09 17:49:14 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | TIME LIMIT EXCEEDED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.00 s | details |
#3 | ACCEPTED | 0.00 s | details |
#4 | ACCEPTED | 0.00 s | details |
#5 | ACCEPTED | 0.00 s | details |
#6 | ACCEPTED | 0.02 s | details |
#7 | ACCEPTED | 0.08 s | details |
#8 | ACCEPTED | 0.06 s | details |
#9 | ACCEPTED | 0.21 s | details |
#10 | ACCEPTED | 0.22 s | details |
#11 | ACCEPTED | 0.00 s | details |
#12 | ACCEPTED | 0.00 s | details |
#13 | TIME LIMIT EXCEEDED | -- | details |
#14 | ACCEPTED | 0.00 s | details |
#15 | ACCEPTED | 0.00 s | details |
#16 | ACCEPTED | 0.35 s | details |
Code
#include <iostream> #include <vector> #include <queue> using namespace std; // Directions: (dx, dy) pairs corresponding to Up, Right, Down, Left const vector<pair<int, int>> directions = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; const vector<char> directionChars = {'U', 'R', 'D', 'L'}; struct Node { int x, y; string path; }; bool isValid(int x, int y, int n, int m, vector<vector<char>>& warehouse, vector<vector<bool>>& visited) { return x >= 0 && y >= 0 && x < n && y < m && warehouse[x][y] != '#' && !visited[x][y]; } int main() { ios::sync_with_stdio(false); // Disable synchronization with C I/O for speed cin.tie(NULL); // Untie cin from cout for faster I/O int n, m; cin >> n >> m; vector<vector<char>> warehouse(n, vector<char>(m)); vector<vector<bool>> visited(n, vector<bool>(m, false)); int startX = -1, startY = -1, endX = -1, endY = -1; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> warehouse[i][j]; if (warehouse[i][j] == 'A') { startX = i; startY = j; } if (warehouse[i][j] == 'B') { endX = i; endY = j; } } } // BFS setup queue<Node> q; q.push({startX, startY, ""}); visited[startX][startY] = true; while (!q.empty()) { Node current = q.front(); q.pop(); // Check if we've reached the exit if (current.x == endX && current.y == endY) { cout << "YES" << endl; cout << current.path.length() << endl; cout << current.path << endl; return 0; } // Explore all 4 directions for (int i = 0; i < 4; i++) { int newX = current.x + directions[i].first; int newY = current.y + directions[i].second; if (isValid(newX, newY, n, m, warehouse, visited)) { visited[newX][newY] = true; q.push({newX, newY, current.path + directionChars[i]}); } } } cout << "NO" << endl; return 0; }
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 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 RDDDDDLDDDDLDDDDLLLLLLDDLLLDDL... 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 DDDDDDDDDDDDDDDDDLDDDDDDDDDDDD... 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: 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: ACCEPTED
input |
---|
1000 1000 A................................ |
correct output |
---|
YES 1998 RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR... |
user output |
---|
YES 1998 RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR... Truncated |