結果
| 問題 |
No.8063 幅優先探索
|
| コンテスト | |
| ユーザー |
chocorusk
|
| 提出日時 | 2020-04-01 22:10:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 47 ms / 2,000 ms |
| コード長 | 1,186 bytes |
| コンパイル時間 | 1,088 ms |
| コンパイル使用メモリ | 117,596 KB |
| 実行使用メモリ | 9,344 KB |
| 最終ジャッジ日時 | 2024-06-27 11:04:51 |
| 合計ジャッジ時間 | 1,679 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 9 |
ソースコード
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int main()
{
int r, c;
cin>>r>>c;
int sy, sx, gy, gx;
cin>>sy>>sx>>gy>>gx;
sy--; gy--; sx--; gx--;
string s[1010];
for(int i=0; i<r; i++) cin>>s[i];
int d[1010][1010];
for(int i=0; i<r; i++) for(int j=0; j<c; j++) d[i][j]=1e9;
d[sy][sx]=0;
queue<P> que;
que.push({sy, sx});
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
while(!que.empty()){
P p=que.front(); que.pop();
int x=p.first, y=p.second;
for(int k=0; k<4; k++){
int x1=x+dx[k], y1=y+dy[k];
if(x1<0 || x1>=r || y1<0 || y1>=c) continue;
if(d[x1][y1]>d[x][y]+1){
d[x1][y1]=d[x][y]+1;
que.push({x1, y1});
}
}
}
cout<<d[gy][gx]<<endl;
return 0;
}
chocorusk