結果
| 問題 |
No.8063 幅優先探索
|
| コンテスト | |
| ユーザー |
y61mpnl
|
| 提出日時 | 2020-04-01 23:24:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,155 bytes |
| コンパイル時間 | 642 ms |
| コンパイル使用メモリ | 69,504 KB |
| 実行使用メモリ | 8,064 KB |
| 最終ジャッジ日時 | 2024-06-27 12:47:28 |
| 合計ジャッジ時間 | 1,706 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 2 WA * 5 RE * 2 |
ソースコード
#include <cstdio>
#include <queue>
#include <string>
#include <vector>
#include <utility>
using namespace std;
static const int INF=1<<29;
static const int di[]={-1, 0, 1, 0};
static const int dj[]={0, -1, 0, 1};
int main() {
int R, C, sy, sx, gy, gx;
scanf("%d %d %d %d %d %d", &R, &C, &sy, &sx, &gy, &gx);
--sy; --sx; --gy; --gx;
vector<string> c(R);
for (int i=0; i<R; ++i) {
char buf[64];
scanf("%s", buf);
c[i] = buf;
}
vector<vector<int>> dp(R, vector<int>(C, INF)); dp[sy][sx]=0;
queue<pair<int, int>> q; q.emplace(sy, sx);
while (!q.empty()) {
int i=q.front().first, j=q.front().second; q.pop();
if (c[i][j] != '.') continue;
for (int k=0; k<4; ++k) {
int I=i+di[k], J=j+dj[k];
if (I < 0 || R <= I || J < 0 || C <= J) continue;
if (dp[I][J] < dp[i][j]) continue;
if (c[I][J] != '.') continue;
if (I == gy && J == gx)
return !printf("%d\n", dp[i][j]+1);
dp[I][J] = dp[i][j] + 1;
c[i][j] = '+';
q.emplace(I, J);
}
}
return 0;
}
y61mpnl