結果

問題 No.3063 幅優先探索
ユーザー a163236a163236
提出日時 2020-04-01 22:53:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,044 bytes
コンパイル時間 1,715 ms
コンパイル使用メモリ 175,264 KB
実行使用メモリ 8,692 KB
最終ジャッジ日時 2023-09-09 19:37:20
合計ジャッジ時間 2,547 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,348 KB
testcase_01 AC 5 ms
8,348 KB
testcase_02 AC 5 ms
8,356 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 66 ms
8,604 KB
testcase_08 AC 5 ms
8,484 KB
testcase_09 AC 6 ms
8,556 KB
testcase_10 AC 5 ms
8,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define _LIBCPP_DEBUG 0
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 30;

vector<vector<char>> MAP(1004,vector<char>(1002,'#'));
vector<vector<int>> dist(1004,vector<int>(1002,INF));

int sy,sx,gy,gx;


void bfs(){
    queue<int> qR; qR.push(sy);
    queue<int> qC; qC.push(sx);

    dist[sy][sx]=0;
    int aR[4] = {1,0,-1,0};
    int aC[4] = {0,1,0,-1};
    while (!qR.empty()){
        int ROW=qR.front(); qR.pop();
        int COL=qC.front(); qC.pop();

        for (int i = 0; i < 4; ++i) {
            if(MAP[ROW+aR[i]][COL+aC[i]]!='#' && dist[ROW+aR[i]][COL+aC[i]]==INF){
                dist[ROW+aR[i]][COL+aC[i]] = dist[ROW][COL]+1;
                qR.push(ROW+aR[i]); qC.push(COL+aC[i]);
            }
        }

    }

}

int main(void){

    int R,C; cin>>R>>C;
    cin>>sy>>sx;
    cin>>gy>>gx;
    for (int i = 1; i <= R; ++i) {
        for (int j = 1; j <= C; ++j) {
            cin>>MAP[i][j];
        }
    }

    bfs();

    cout<<dist[gy][gx]<<endl;

    return 0;
}
0