Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ID: mickyta1
- TASK: maze1
- LANG: C++
- */
- #include <bits/stdc++.h>
- using namespace std;
- #define f first
- #define s second
- typedef pair<int, int> pii;
- typedef pair<pii, int> ppi;
- const pii dir[4] = {pii(0, 1), pii(0, -1), pii(1, 0), pii(-1, 0)};
- const int R = 200 + 5;
- const int C = 76 + 5;
- int row, col;
- char board[R][C];
- bool visited[R][C];
- bool isInBoard(const pii &x){
- return 2 <= x.f && x.f <= row && 2 <= x.s && x.s <= col;
- }
- int main(){
- freopen("maze1.in", "r", stdin);
- freopen("maze1.out", "w", stdout);
- scanf("%d%d%*c", &col, &row);
- row *= 2;
- col *= 2;
- for(int i = 1; i <= row + 1; ++i){
- for(int j = 1; j <= col + 1; ++j){
- scanf("%c", &board[i][j]);
- }
- scanf("%*c");
- }
- queue<ppi> que;
- for(int i = 2; i <= row; i += 2){
- visited[i][0] = true;
- que.emplace(pii(i, 0), 0);
- visited[i][col + 2] = true;
- que.emplace(pii(i, col + 2), 0);
- }
- for(int j = 2; j <= col; j += 2){
- visited[0][j] = true;
- que.emplace(pii(0, j), 0);
- visited[row + 2][j] = true;
- que.emplace(pii(row + 2, j), 0);
- }
- int mx = 0;
- while(!que.empty()){
- pii u = que.front().f;
- int dt = que.front().s;
- que.pop();
- mx = max(mx, dt);
- for(int d = 0; d < 4; ++d){
- pii obs = pii(u.f + dir[d].f, u.s + dir[d].s);
- pii v = pii(u.f + 2 * dir[d].f, u.s + 2 * dir[d].s);
- if(isInBoard(v) && board[obs.f][obs.s] == ' ' && !visited[v.f][v.s]){
- visited[v.f][v.s] = true;
- que.emplace(v, dt + 1);
- }
- }
- }
- cout << mx << '\n';
- fclose(stdin);
- fclose(stdout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement