Submission #3417398
Source Code Expand
#include <iostream> #include <queue> using namespace std; struct position{ int cx; int cy; }; queue <struct position> q; void initialize(int sx, int sy){ struct position current; current.cx = sx; current.cy = sy; q.push(current); } void nextcheck(char maze[52][52], int ans[52][52], int *x){ if(q.empty() == 1){ *x = 1; return; } struct position current = q.front(); struct position next; if(maze[current.cx +1][current.cy] == '.'){ next.cx = current.cx + 1; next.cy = current.cy; ans[next.cx][next.cy] = ans[current.cx][current.cy] + 1; q.push(next); } if(maze[current.cx][current.cy+1] == '.'){ next.cx = current.cx; next.cy = current.cy + 1; ans[next.cx][next.cy] = ans[current.cx][current.cy] + 1; q.push(next); } if(maze[current.cx-1][current.cy] == '.'){ next.cx = current.cx - 1; next.cy = current.cy; ans[next.cx][next.cy] = ans[current.cx][current.cy] + 1; q.push(next); } if(maze[current.cx][current.cy-1] == '.'){ next.cx = current.cx; next.cy = current.cy - 1; ans[next.cx][next.cy] = ans[current.cx][current.cy] + 1; q.push(next); } maze[current.cx][current.cy] = '#'; q.pop(); } int main(void){ int R, C, sy, sx, gy, gx, flag=0, i, j; cin >> R >> C; cin >> sy >> sx; cin >> gy >> gx; char maze[52][52]; int ans[52][52]; for(i=1; i<=R; i++){ for(j=1; j<=C; j++){ cin >> maze[i][j]; ans[i][j] = 0; } } initialize(sx, sy); while(1){ nextcheck(maze, ans, &flag); if(flag == 1) break; } cout << ans[gy][gx] << "\n"; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - 幅優先探索 |
User | sugibad1412 |
Language | C++ (GCC 5.4.1) |
Score | 0 |
Code Size | 1664 Byte |
Status | TLE |
Exec Time | 2151 ms |
Memory | 804052 KB |
Judge Result
Set Name | Sample | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 100 | ||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | subtask0_sample01.txt, subtask0_sample02.txt, subtask0_sample03.txt |
All | subtask0_sample01.txt, subtask0_sample02.txt, subtask0_sample03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask1_21.txt, subtask1_22.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
subtask0_sample01.txt | AC | 1 ms | 256 KB |
subtask0_sample02.txt | AC | 1 ms | 256 KB |
subtask0_sample03.txt | TLE | 2150 ms | 791608 KB |
subtask1_01.txt | AC | 1 ms | 256 KB |
subtask1_02.txt | AC | 1 ms | 256 KB |
subtask1_03.txt | AC | 1 ms | 256 KB |
subtask1_04.txt | TLE | 2150 ms | 792696 KB |
subtask1_05.txt | TLE | 2150 ms | 794364 KB |
subtask1_06.txt | TLE | 2123 ms | 333000 KB |
subtask1_07.txt | AC | 1 ms | 256 KB |
subtask1_08.txt | AC | 1 ms | 256 KB |
subtask1_09.txt | TLE | 2131 ms | 453428 KB |
subtask1_10.txt | AC | 1 ms | 256 KB |
subtask1_11.txt | TLE | 2151 ms | 804052 KB |
subtask1_12.txt | TLE | 2146 ms | 714132 KB |
subtask1_13.txt | AC | 69 ms | 2872 KB |
subtask1_14.txt | AC | 1 ms | 256 KB |
subtask1_15.txt | TLE | 2113 ms | 170068 KB |
subtask1_16.txt | AC | 349 ms | 23348 KB |
subtask1_17.txt | TLE | 2139 ms | 592260 KB |
subtask1_18.txt | TLE | 2122 ms | 330852 KB |
subtask1_19.txt | AC | 1 ms | 256 KB |
subtask1_20.txt | AC | 1 ms | 256 KB |
subtask1_21.txt | TLE | 2144 ms | 701688 KB |
subtask1_22.txt | AC | 3 ms | 384 KB |