Task: | Abandoned warehouse |
Sender: | Rasse |
Submission time: | 2024-09-09 17:31:04 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | ACCEPTED |
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.03 s | details |
#7 | ACCEPTED | 0.05 s | details |
#8 | ACCEPTED | 0.05 s | details |
#9 | ACCEPTED | 0.04 s | details |
#10 | ACCEPTED | 0.04 s | details |
#11 | ACCEPTED | 0.00 s | details |
#12 | ACCEPTED | 0.00 s | details |
#13 | ACCEPTED | 0.06 s | details |
#14 | ACCEPTED | 0.00 s | details |
#15 | ACCEPTED | 0.00 s | details |
#16 | ACCEPTED | 0.04 s | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:57:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 57 | if (x < map[y].size() - 1 && (map[y][x+1] == '.' || map[y][x+1] == 'A')) | ~~^~~~~~~~~~~~~~~~~~~ input/code.cpp:63:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare] 63 | if (y < map.size() - 1 && (map[y+1][x] == '.' || map[y+1][x] == 'A')) | ~~^~~~~~~~~~~~~~~~ input/code.cpp:94:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 94 | for (int i = 0; i < ans.size(); i++) | ~~^~~~~~~~~~~~ input/code.cpp:80:26: warning: 'endX' may be used uninitialized in...
Code
// Online C++ compiler to run C++ program online #include <iostream> #include <algorithm> #include <vector> #include <queue> using namespace std; int main() { // Write C++ code here int n, m; // height, width std::cin >> n >> m; vector<vector<char>> map = vector<vector<char>>(n, vector<char>(m, 0)); int startX, startY = 0; int endX, endY = 0; for (int y = 0; y < n; y++) { string line; std::cin >> line; for (int x = 0; x < m; x++) { map[y][x] = line[x]; if (line[x] == 'A') { startX = x; startY = y; } else if (line[x] == 'B') { endX = x; endY = y; } } } queue<pair<int, int>> que = queue<pair<int, int>>(); que.push({endX, endY}); while (!que.empty()) { pair<int, int> coord = que.front(); que.pop(); int y = coord.second; int x = coord.first; if (y > 0 && (map[y-1][x] == '.' || map[y-1][x] == 'A')) { map[y-1][x] = 'D'; que.push({x, y-1}); } if (x > 0 && (map[y][x-1] == '.' || map[y][x-1] == 'A')) { map[y][x-1] = 'R'; que.push({x-1, y}); } if (x < map[y].size() - 1 && (map[y][x+1] == '.' || map[y][x+1] == 'A')) { map[y][x + 1] = 'L'; que.push({x+1, y}); } if (y < map.size() - 1 && (map[y+1][x] == '.' || map[y+1][x] == 'A')) { map[y+1][x] = 'U'; que.push({x, y+1}); } } if (map[startY][startX] == 'A') { std::cout << "NO"; } else { vector<char> ans = vector<char>(); std::cout << "YES" << std::endl; int x = startX; int y = startY; while (x != endX || y != endY) { ans.push_back(map[y][x]); if (map[y][x] == 'L') x--; else if (map[y][x] == 'U') y--; else if (map[y][x] == 'R') x++; else if (map[y][x] == 'D') y++; } cout << ans.size() << endl; for (int i = 0; i < ans.size(); i++) cout << ans[i]; } /* cout << endl; for (int y = 0; y < n; y++) { for (int x = 0; x < m; x++) std::cout << map[y][x]; std::cout << 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 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 |