Submission #4316393
Source Code Expand
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define MM 1000000000 #define MOD MM+7 #define MAX 10000 #define MAP 100 #define MAX_N 100000 #define Pair pair<int,int> int dx[4] = {-1, 0, 1, 0}; int dy[4] = {0, -1, 0, 1}; int dist[MAP][MAP]; int h[MAX_N]; int dp[MAX_N]; int R,C; Pair s, g; char c[MAP][MAP]; 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 < W; j++){ dist[i][j] = MM; } } dist[s.first-1][s.second-1] = 0; for(int i = 0; i < 4; i++){ Pair p = que.front(); que.pop(); int ny = p.first + dy[i]; int nx = p.second + dx[i]; if(0<=nx && nx<10 && 0<=ny && ny<10 && c[ny][nx] == '.'){ que.push(Pair(ny,nx)); dist[ny][nx] = 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 < R; 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 | 1223 Byte |
Status | CE |
Compile Error
./Main.cpp: In function ‘int bfs()’: ./Main.cpp:22:28: error: ‘W’ was not declared in this scope for(int j = 0; j < W; j++){ ^