結果
問題 |
No.424 立体迷路
|
ユーザー |
![]() |
提出日時 | 2016-09-22 22:57:30 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,883 bytes |
コンパイル時間 | 764 ms |
コンパイル使用メモリ | 86,264 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-17 15:04:22 |
合計ジャッジ時間 | 1,614 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 16 WA * 5 |
ソースコード
#include <iostream> #include <string> #include <algorithm> #include <functional> #include <vector> #include <stack> #include <queue> #include <set> #include <bitset> #include <map> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> using namespace std; typedef long long ll; typedef pair<int,int> pint; typedef vector<int> vint; typedef vector<pint> vpint; #define mp make_pair #define fi first #define se second #define all(v) (v).begin(),(v).end() #define rep(i,n) for(int i=0;i<(n);i++) #define reps(i,f,n) for(int i=(f);i<(n);i++) int dy[] = {1, 0, -1, 0}; int dx[] = {0, 1, 0, -1}; int h, w, sx, sy, gx, gy; string b[55]; bool used[55][55]; int main(void){ cin >> h >> w >> sy >> sx >> gy >> gx; sx--; sy--; gx--; gy--; rep(i, h) cin >> b[i]; rep(i, 55)rep(j, 55){ used[i][j] = false; } queue<pair<int, int> > q; q.push(make_pair(sy, sx)); // printf("%d %d\n", sy, sx); used[sy][sx] = true; while(!q.empty()){ auto n = q.front(); q.pop(); if(n.fi == gy && n.se == gx) break; int hh = b[n.fi][n.se] - '0'; // printf("%d %d %d\n", n.fi, n.se, hh); rep(i, 4){ int ny = n.fi + dy[i], nx = n.se + dx[i]; // printf("1 ; %d %d\n", ny, nx); // printf("h %d w %d\n", h, w); if(!(0 <= ny && ny < h && 0 <= nx && nx < w)) continue; // printf("%d %d\n", ny, nx); if(used[ny][nx]) continue; int nh = b[ny][nx] - '0'; // printf("2 : %d %d %d\n", ny, nx, nh); if(abs(nh - hh) <= 1){ used[ny][nx] = true; q.push(make_pair(ny, nx)); } } rep(i, 4){ int ny = n.fi + 2 * dy[i], nx = n.se + 2 * dx[i]; if(!(0 <= ny && ny < h && 0 <= nx && nx < w)) continue; if(used[ny][nx]) continue; int ah = b[(ny + n.fi) / 2][(nx + n.se) / 2] - '0'; if(hh - ah >= 0){ used[ny][nx] = true; q.push(make_pair(ny, nx)); } } } if(used[gy][gx]) printf("YES\n"); else printf("NO\n"); return 0; }