結果

問題 No.424 立体迷路
ユーザー tnakao0123
提出日時 2016-09-25 00:22:01
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,708 bytes
コンパイル時間 726 ms
コンパイル使用メモリ 92,004 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-05 07:09:58
合計ジャッジ時間 1,294 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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

/* -*- coding: utf-8 -*-
*
* 424.cc: No.424 - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_H = 50;
const int MAX_W = 50;
const int dxs[] = {1, 0, -1, 0}, dys[] = {0, -1, 0, 1};
/* typedef */
typedef pair<int,int> pii;
/* global variables */
int flds[MAX_H][MAX_W];
bool ds[MAX_H][MAX_W];
/* subroutines */
/* main */
int main() {
int h, w;
cin >> h >> w;
int sx, sy, gx, gy;
cin >> sx >> sy >> gx >> gy;
sx--, sy--, gx--, gy--;
for (int x = 0; x < h; x++) {
string s;
cin >> s;
for (int y = 0; y < w; y++) flds[x][y] = s[y] - '0';
}
ds[sx][sy] = true;
queue<pii> q;
q.push(pii(sx, sy));
while (! q.empty()) {
pii u = q.front(); q.pop();
int &ux = u.first, &uy = u.second;
if (ux == gx && uy == gy) break;
int uf = flds[ux][uy];
for (int di = 0; di < 4; di++) {
int vx = ux + dxs[di], vy = uy + dys[di];
if (vx >= 0 && vx < h && vy >= 0 && vy < w && ! ds[vx][vy]) {
int &vf = flds[vx][vy];
if (vf >= uf - 1 && vf <= uf + 1) {
ds[vx][vy] = true;
q.push(pii(vx, vy));
}
}
int vx1 = vx + dxs[di], vy1 = vy + dys[di];
if (vx1 >= 0 && vx1 < h && vy1 >= 0 && vy1 < w && ! ds[vx1][vy1] &&
flds[vx1][vy1] == uf && flds[vx][vy] < uf) {
ds[vx1][vy1] = true;
q.push(pii(vx1, vy1));
}
}
}
cout << (ds[gx][gy] ? "YES" : "NO") << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0