結果
問題 | No.424 立体迷路 |
ユーザー |
|
提出日時 | 2016-09-23 00:30:41 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,159 bytes |
コンパイル時間 | 828 ms |
コンパイル使用メモリ | 98,996 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 07:07:23 |
合計ジャッジ時間 | 1,410 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
#include <vector>#include <list>#include <map>#include <set>#include <deque>#include <stack>#include <queue>#include <bitset>#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <sstream>#include <iostream>#include <iomanip>#include <cstdio>#include <cmath>#include <cstdlib>#include <cctype>#include <string>#include <cstring>#include <ctime>using namespace std;inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}typedef vector<int> VI;typedef vector<VI> VVI;typedef vector<string> VS;typedef pair<int, int> PII;typedef long long LL;#define FOR(i,a,b) for(int i=(a);i<(b);++i)#define REP(i,n) FOR(i,0,n)#define MP make_pair#define MT make_tuple#define EACH(i,c) for(auto i: c)#define SORT(c) sort((c).begin(),(c).end())#define ALL(a) (a).begin(),(a).end()#define RALL(a) (a).rbegin(), (a).rend()#define CUR cur.first][cur.second#define NEXT next.first][next.second#define FAR far.first][far.secondint main() {int h, w;cin >> h >> w;int sx, sy, gx, gy;cin >> sx >> sy >> gx >> gy;sx--;sy--;gx--;gy--;VS S(h);REP(i, h) cin >> S[i];VVI done(h, VI(w, 0));queue<PII> que;que.push(MP(sx, sy));int dx[] = {0, 1, 0, -1};int dy[] = {1, 0, -1, 0};while(!que.empty()){PII cur = que.front();que.pop();REP(i, 4){PII next = MP(cur.first + dx[i], cur.second + dy[i]);if(next.first < 0 || h <= next.first) continue;if(next.second < 0 || w <= next.second) continue;if(abs(S[CUR] - S[NEXT]) <= 1){if(!done[NEXT]){que.push(next);done[NEXT] = true;}}PII far = MP(next.first + dx[i], next.second + dy[i]);if(far.first < 0 || h <= far.first) continue;if(far.second < 0 || w <= far.second) continue;if(S[CUR] >= S[NEXT] && S[CUR] == S[FAR]){if(!done[FAR]){que.push(far);done[FAR] = true;}}}}// EACH(d, done){// EACH(a, d) cout << a;// cout << endl;// }if(done[gx][gy]) cout << "YES" << endl;else cout << "NO" << endl;return 0;}