Submission #4309808


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pair;
#define MM 1000000000
#define MOD MM+7
#define MAX 10000
#define MAP 51
#define GRAPH 10
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int n,m;
int R,C;
int Map[10][10];
int dist[50][50];
char c[50][50];
dist[50][50];
Pair s, g;
int bfs(){
    queue<Pair> que;
    que.push(Pair(s.first-1, s.second-1));

    for(int i = 0; i < R; i++){
        for(int j = 0; j < C; j++){
            dist[i][j] = MAX;
        }
    }
    while(que.size()){
        Pair p = que.front();
        que.pop();
        if(p.first == g.first-1 && p.second == g.second-1) break;
        for(int i = 0; i < 4; i++){
            int nx = s.first + dx[i];
            int ny = s.second + dy[i];
            if(c[nx][ny] == '.' && dist[nx][ny] == MAX){
                que.push(Pair(nx,ny));
                dist[nx][ny] = dist[p.first][p.second]+1;
            }
        }
    }
    return dist[g.first-1][g.second-1];
}
int main(){
    cin >> R >> C;
    cin >> s.first >> s.second;
    cin >> g.first >> g.second;
    for(int i = 0; i < R; i++){
        for(int j = 0; j < C; j++){
            cin >> c[i][j];
        }
    }
    int ans = bfs();
    cout << ans << endl;
}

Submission Info

Submission Time
Task C - 幅優先探索
User Kant
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1307 Byte
Status CE

Compile Error

./Main.cpp:17:1: error: ‘dist’ does not name a type
 dist[50][50];
 ^