Submission #162144


Source Code Expand

#include<iostream>
#include<queue>
#include<utility>
int map[50][50];

int main(){
  int R,C;
  int sy,sx,gy,gx;
  std::cin >> R >> C >> sy >> sx >> gy >> gx:
  for(int i=0;i<R;i++){
    for(int j=0;j<C;j++){
      char c;
      std::cin >> c;
      if(c=='#')map[i][j]=-1;
    }
  }
  std::queue<std::pair<std::pair<int,int>,int> > q;
  q.push(std::make_pair(std::make_pair(sy-1,sx-1),1));
  while(!q.empty()){
    std::pair<std::pair<int,int>,int> p=q.top();
    q.pop();
    if(p.first.first<0 || p.first.first >= R || p.first.second<0 || p.first.second >= C)continue;
    if(map[p.first.first][p.second.second]<=0)continue;
    if(p.first.first==gy-1 && p.first.second==gx-1){
      std::cout << p.second-1 << std::endl;
      return 0;
    }
    map[p.first.first][p.first.second]=p.second;
    q.push(std::make_pair(std::make_pair(p.first.first-1,p.first.second),p.second+1);
    q.push(std::make_pair(std::make_pair(p.first.first+1,p.first.second),p.second+1);
    q.push(std::make_pair(std::make_pair(p.first.first,p.first.second-1),p.second+1);
    q.push(std::make_pair(std::make_pair(p.first.first,p.first.second+1),p.second+1);
  }
  return 0;
}

Submission Info

Submission Time
Task C - 幅優先探索
User phi16
Language C++ (G++ 4.6.4)
Score 0
Code Size 1191 Byte
Status CE

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:9:45: error: expected ‘;’ before ‘:’ token
./Main.cpp:10:15: error: ‘i’ was not declared in this scope
./Main.cpp:10:22: error: expected ‘;’ before ‘)’ token
./Main.cpp:35:1: error: expected ‘}’ at end of input