結果
問題 | No.424 立体迷路 |
ユーザー |
![]() |
提出日時 | 2016-09-23 00:05:48 |
言語 | C++11 (gcc 13.3.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,977 bytes |
コンパイル時間 | 842 ms |
コンパイル使用メモリ | 91,104 KB |
実行使用メモリ | 542,464 KB |
最終ジャッジ日時 | 2024-11-17 15:15:43 |
合計ジャッジ時間 | 7,531 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 MLE * 1 |
other | AC * 19 TLE * 1 MLE * 1 |
ソースコード
#include "math.h" #include <algorithm> #include <complex> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> #define ifor(i, a, b) for (int i = (a); i < (b); i++) #define rfor(i, a, b) for (int i = (b)-1; i >= (a); i--) #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) using namespace std; typedef long double ld; typedef long long int lli; const double eps = 1e-11; int vex[4] = {1, 0, -1, 0}; int vey[4] = {0, 1, 0, -1}; typedef vector<double> Vec; typedef vector<int> vec; typedef vector<Vec> MAT; typedef vector<vec> mat; lli MOD = 1000000007; int used[55][55]; int fed[55][55]; struct P { int x, y; P(int x, int y) { this->x = x, this->y = y; } }; int h, w; bool inrange(int x, int y) { return x >= 0 && x < w && y < h && y >= 0; } int main() { int sx, sy, gx, gy; cin >> h >> w >> sx >> sy >> gx >> gy; queue<P> que; que.push(P(sy - 1, sx - 1)); char c; rep(i, h) rep(j, w) { cin >> c; fed[j][i] = c - '0'; } while (!que.empty()) { P p = que.front(); que.pop(); used[p.x][p.y] = 1; rep(i, 4) { if (inrange(p.x + vex[i], p.y + vey[i]) && abs(fed[p.x][p.y] - fed[p.x + vex[i]][p.y + vey[i]]) <= 1 && !used[p.x + vex[i]][p.y + vey[i]]) { que.push(P(p.x + vex[i], p.y + vey[i])); } if (inrange(p.x + 2 * vex[i], p.y + 2 * vey[i]) && abs(fed[p.x][p.y] - fed[p.x + 2 * vex[i]][p.y + 2 * vey[i]]) == 0 && fed[p.x][p.y] - fed[p.x + vex[i]][p.y + vey[i]] > 0 && !used[p.x + 2 * vex[i]][p.y + 2 * vey[i]]) { que.push(P(p.x + 2 * vex[i], p.y + 2 * vey[i])); } } } /* rep(i, h) rep(j, w) { cout << used[j][i]; if (j == w - 1) cout << endl; } */ cout << (used[gy - 1][gx - 1] ? "YES" : "NO"); cout << endl; }