Task: | Abandoned warehouse |
Sender: | bielaltes |
Submission time: | 2024-09-09 17:37: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.06 s | details |
#7 | ACCEPTED | 0.12 s | details |
#8 | ACCEPTED | 0.10 s | details |
#9 | ACCEPTED | 0.26 s | details |
#10 | ACCEPTED | 0.25 s | details |
#11 | ACCEPTED | 0.01 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.39 s | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:56:23: warning: variable 'bx' set but not used [-Wunused-but-set-variable] 56 | int n, m, ax, ay, bx, by; | ^~ input/code.cpp:56:27: warning: variable 'by' set but not used [-Wunused-but-set-variable] 56 | int n, m, ax, ay, bx, by; | ^~ input/code.cpp:80:8: warning: 'ay' may be used uninitialized in this function [-Wmaybe-uninitialized] 80 | bfs(map, ax, ay, n, m); | ~~~^~~~~~~~~~~~~~~~~~~ input/code.cpp:80:8: warning: 'ax' may be used uninitialized in this function [-Wmaybe-uninitialized]
Code
#include <iostream> #include <vector> #include <algorithm> #include <queue> #include <bits/stdc++.h> using namespace std; void bfs(vector< vector<char> >& map,int ax,int ay,int n,int m) { vector< vector< bool> > visited = vector<vector<bool> >(n, vector<bool>(m, false)); queue<pair<pair<int, int>, string> > q; q.push(make_pair(make_pair(ax, ay), "")); while (!q.empty()){ auto aux = q.front(); q.pop(); int nx = aux.first.first, ny = aux.first.second; //cout << nx << " " << ny << endl; visited[nx][ny] = true; if (map[nx][ny] == 'B') { cout << "YES" << endl; cout << aux.second.size() << endl; cout << aux.second << endl; return; } if (nx -1 >= 0 and map[nx -1][ny] != '#' and !visited[nx-1][ny]) { q.push(make_pair(make_pair(nx-1, ny), aux.second + 'U')); visited[nx-1][ny] = true; } if ( nx +1< n and map[nx +1][ny] != '#' and !visited[nx+1][ny]){ q.push(make_pair(make_pair(nx+1, ny), aux.second + 'D')); visited[nx+1][ny] = true; } if (ny-1 >= 0 and map[nx][ny-1] != '#' and !visited[nx][ny-1]) { q.push(make_pair(make_pair(nx, ny-1), aux.second + 'L')); visited[nx][ny-1] = true; } if (ny+1 < m and map[nx][ny+1] != '#' and !visited[nx][ny+1]){ q.push(make_pair(make_pair(nx, ny+1), aux.second + 'R')); visited[nx][ny+1] = true; } } cout << "NO" << endl; } int main() { int n, m, ax, ay, bx, by; cin >> n >> m; vector< vector<char> > map = vector<vector<char> >(n); for (int i = 0; i < n; ++i) { char aux; for (int j = 0; j < m; ++j) { cin >> aux; if (aux == 'A'){ ax = i; ay = j; } else if (aux == 'B') { bx = i; by = j; } map[i].push_back(aux); } } bfs(map, ax, ay, n, m); }
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 DDR |
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 LLLDDRDDDDDDLLDDLLDDDLDDLLLDDL... 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 DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD... Truncated |