結果

問題 No.424 立体迷路
ユーザー femtofemto
提出日時 2016-09-22 22:39:24
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,268 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 88,540 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-05 07:00:55
合計ジャッジ時間 1,385 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <queue>
using namespace std;
int h, w, sx, sy, gx, gy;
int b[50][50];
bool visited[50][50];
typedef pair<int, int> P;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
bool in(int x, int y) {
return 0 <= x && x < w && 0 <= y && y < h;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> h >> w >> sy >> sx >> gy >> gx;
sx--, sy--, gx--, gy--;
for(int i = 0; i < h; i++) {
for(int j = 0; j < w; j++) {
char c;
cin >> c;
b[i][j] = c - '0';
}
}
queue<P> q;
q.push(P(sx, sy));
visited[sy][sx] = true;
while(q.size()) {
int x = q.front().first, y = q.front().second;
q.pop();
for(int i = 0; i < 4; i++) {
int nx = x + dx[i], ny = y + dy[i];
if(in(nx, ny) && !visited[ny][nx] && abs(b[ny][nx] - b[y][x]) <= 1) {
visited[ny][nx] = true;
q.push(P(nx, ny));
}
int nnx = nx + dx[i], nny = ny + dy[i];
if(in(nnx, nny) && !visited[nny][nnx] && b[nny][nnx] == b[y][x] && b[y][x] > b[ny][nx]) {
visited[nny][nnx] = true;
q.push(P(nnx, nny));
}
}
}
if(visited[gy][gx]) {
cout << "YES" << endl;
}
else {
cout << "NO" << endl;
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0