結果

問題 No.3063 幅優先探索
ユーザー FSMFSM
提出日時 2020-04-01 21:40:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,746 bytes
コンパイル時間 2,053 ms
コンパイル使用メモリ 205,788 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-09 17:20:30
合計ジャッジ時間 3,152 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0