Task: | Abandoned warehouse |
Sender: | minghao |
Submission time: | 2024-09-09 17:07:53 +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.04 s | details |
#9 | ACCEPTED | 0.06 s | details |
#10 | ACCEPTED | 0.05 s | details |
#11 | ACCEPTED | 0.01 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.06 s | details |
Compiler report
input/code.cpp: In function 'void Test()': input/code.cpp:69:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result] 69 | freopen("temp\\in.txt", "r", stdin); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~ input/code.cpp: In function 'int main()': input/code.cpp:74:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result] 74 | scanf("%d%d", &n, &m); | ~~~~~^~~~~~~~~~~~~~~~
Code
#include<iostream> #include<cstdio> #include<queue> #include<string> #include<stack> typedef long long LL; typedef std::pair<int,int> poi; const int N=1005; using namespace std; int des[4][2]={{-1,0},{0,1},{1,0},{0,-1}}; // U R L D char reverse_des[4]={'U', 'R', 'D', 'L'}; int n, m, dis[N][N], parent[N][N]; poi start_poi, end_poi; bool map[N][N], vis[N][N]; bool Check(int x, int y) { if(x < 1 || x > n || y < 1 || y > m) return false; if(vis[x][y] || map[x][y]) return false; return true; } bool BFS() { std::queue<poi> q; // Start point int u = start_poi.first, v = start_poi.second; vis[u][v] = true; dis[u][v] = 0; q.push(start_poi); while(!q.empty()) { poi p = q.front(); q.pop(); //Check if(p == end_poi) break; //Expand int u = p.first, v = p.second; for(int i=0; i<4; i++) { int x = u+des[i][0], y = v+des[i][1]; if(Check(x, y)) { vis[x][y] = true; dis[x][y] = dis[u][v] + 1; parent[x][y] = i; q.push(std::make_pair(x, y)); } } } if(vis[end_poi.first][end_poi.second]) return true; else return false; } void Test() { freopen("temp\\in.txt", "r", stdin); } int main() { // Test(); scanf("%d%d", &n, &m); getchar(); for(int i=1; i<=n; i++) { std::string s; std::getline(std::cin, s); for(int j=1; j<=m; j++) { if(s[j-1] == '#') map[i][j] = 1; if(s[j-1] == 'A') start_poi = std::make_pair(i, j); if(s[j-1] == 'B') end_poi = std::make_pair(i, j); } } if(BFS()) { printf("YES\n"); printf("%d\n", dis[end_poi.first][end_poi.second]); std::stack<char> ans; poi now = end_poi; while(now != start_poi) { int way = parent[now.first][now.second]; ans.push(reverse_des[way]); now.first-=des[way][0]; now.second-=des[way][1]; } while(!ans.empty()) { char c = ans.top(); ans.pop(); putchar(c); } } else { printf("NO"); } 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: 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 |