結果
| 問題 |
No.8063 幅優先探索
|
| コンテスト | |
| ユーザー |
FSM
|
| 提出日時 | 2020-04-01 21:40:13 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,746 bytes |
| コンパイル時間 | 2,117 ms |
| コンパイル使用メモリ | 198,900 KB |
| 最終ジャッジ日時 | 2025-01-09 11:48:15 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 4 WA * 3 RE * 2 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long double ld;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;
char m[60][60];
int dis[60][60];
bool v[60][60];
void solve(){
int r,c;
int sy,sx;
int gy,gx;
cin >> r >> c;
cin >> sy >> sx;
cin >> gy >> gx;
sy--;
sx--;
gy--;
gx--;
rep(i,r){
string st;
cin >> st;
rep(j,c){
m[i][j]=st[j];
}
}
rep(i,60){
rep(j,60){
dis[i][j]=0;
v[i][j]=false;
}
}
queue<pair<int,int>> q;
q.push(make_pair(sy,sx));
dis[sy][sx]=0;
v[sy][sx]=true;
while(!q.empty()){
int y = q.front().first;
int x = q.front().second;
//cout << y << ", " << x << endl;
v[y][x]=true;
q.pop();
if(m[y+1][x]=='.'){
q.push(make_pair(y+1,x));
dis[y+1][x]=dis[y][x]+1;
m[y+1][x]='#';
//q.pop(make_pair(y+1,x));
}
if(m[y-1][x]=='.'){
q.push(make_pair(y-1,x));
dis[y-1][x]=dis[y][x]+1;
m[y-1][x]='#';
//q.pop(make_pair(y-1,x));
}
if(m[y][x+1]=='.'){
q.push(make_pair(y,x+1));
dis[y][x+1]=dis[y][x]+1;
m[y][x+1]='#';
//q.pop(make_pair(y,x+1));
}
if(m[y][x-1]=='.'){
q.push(make_pair(y,x-1));
dis[y][x-1]=dis[y][x]+1;
m[y][x-1]='#';
//q.pop(make_pair(y,x-1));
}
}
cout << dis[gy][gx] << endl;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
}
FSM