結果
問題 | No.424 立体迷路 |
ユーザー |
![]() |
提出日時 | 2017-04-28 19:56:56 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,498 bytes |
コンパイル時間 | 1,116 ms |
コンパイル使用メモリ | 163,568 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 07:14:18 |
合計ジャッジ時間 | 1,804 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define FOR(i,a,b) for(int i=(a);i<(b);i++)#define REP(i,n) FOR(i,0,n)#define ALL(v) (v).begin(),(v).end()template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }typedef unsigned long long ull;typedef long long ll;typedef pair<int, int> pii;typedef pair<ll, ll> pll;typedef pair<int, pii> P;const ll INF = 1ll<<60;const ll MOD = 1000000007;const double EPS = 1e-10;int h, w;int sx, sy, gx, gy;string maps[50];bool done[50][50];int main() {cin >> h >> w;cin >> sy >> sx >> gy >> gx;sx--; sy--; gx--; gy--;REP(i, h) cin >> maps[i];queue<pii> que;que.push(pii(sx, sy));while (!que.empty()) {int x = que.front().first;int y = que.front().second;que.pop();if (done[y][x]) continue;done[y][x] = true;int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};REP(t, 2) {REP(i, 4) {int nx = x + dx[i] * (t + 1);int ny = y + dy[i] * (t + 1);if (!(nx >= 0 && nx < w && ny >= 0 && ny < h)) continue;if (done[ny][nx]) continue;if (t == 0) {if (abs(maps[y][x] - maps[ny][nx]) > 1) continue;}else {if (maps[y][x] != maps[ny][nx] || maps[y + dy[i]][x + dx[i]] > maps[y][x]) continue;}que.push(pii(nx, ny));}}}puts(done[gy][gx] ? "YES" : "NO");return 0;}