제출 #675333

#제출 시각아이디문제언어결과실행 시간메모리
675333vjudge1포탈들 (BOI14_portals)C++14
20 / 100
6 ms3412 KiB
#include <bits/stdc++.h> using namespace std; int R, C, i, j; char lab[1005][1005]; int wx[1005][1005][2], wy[1005][1005][2]; int t[1005][1005]; int cx, cy; queue< pair<int, int> > q; void bfs(int x, int y) { if (x >= 0 && y >= 0 && x < C && y < R && t[y][x] == -1 && lab[y][x] != '#') { t[y][x] = t[j][i] + 1; q.push(make_pair(x, y)); } } int main() { cin >> R >> C; for(int j = 0; j < R; j++) { for(int i = 0; i < C; i++) cin >> lab[j][i]; for(int i = 0; i < C; i++) { t[j][i] = -1; if(lab[j][i] == 'S') {t[j][i] = 0; q.push(make_pair(i, j));} if(lab[j][i] == 'C') {cx = i; cy = j;} } } for(int j = 0; j < R; j++) for(int i = 0; i < C; i++) { wy[j][i][0] = (j == 0 || lab[j-1][i] == '#') ? j : wy[j-1][i][0]; wx[j][i][0] = (i == 0 || lab[j][i-1] == '#') ? i : wx[j][i-1][0]; } for(int j = R-1; j >= 0; j--) for(int i = C-1; i >= 0; i--) { wy[j][i][1] = (j == R-1 || lab[j+1][i] == '#') ? j : wy[j+1][i][1]; wx[j][i][1] = (i == C-1 || lab[j][i+1] == '#') ? i : wx[j][i+1][1]; } while (q.size() && t[cy][cx] == -1) { i = q.front().first; j = q.front().second; q.pop(); bfs(i, j-1); bfs(i, j+1); bfs(i-1, j); bfs(i+1, j); if (wx[j][i][0] == i || wx[j][i][1] == i || wy[j][i][0] == j || wy[j][i][1] == j) { bfs(wx[j][i][0], j); bfs(wx[j][i][1], j); bfs(i, wy[j][i][0]); bfs(i, wy[j][i][1]); } } cout << t[cy][cx]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...