結果
問題 | No.424 立体迷路 |
ユーザー |
![]() |
提出日時 | 2016-09-29 22:29:11 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,104 bytes |
コンパイル時間 | 1,512 ms |
コンパイル使用メモリ | 180,692 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 07:10:36 |
合計ジャッジ時間 | 2,248 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define int long long // <-----!!!!!!!!!!!!!!!!!!!#define rep(i,n) for (int i=0;i<(n);i++)#define rep2(i,a,b) for (int i=(a);i<(b);i++)#define rrep(i,n) for (int i=(n)-1;i>=0;i--)#define all(a) (a).begin(),(a).end()#define rall(a) (a).rbegin(),(a).rend()#define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}#define printP(p) cout << p.first << " " << p.second << endl#define printVP(vp) for(auto&& p : vp) printP(p);typedef long long ll;typedef pair<int, int> Pii;typedef tuple<int, int, int> TUPLE;typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<vvi> vvvi;typedef vector<Pii> vp;const int inf = 1e9;const int mod = 1e9 + 7;int H, W;int sx, sy, gx, gy;vector<string> s;int dx[4] = {1, 0, -1, 0};int dy[4] = {0, 1, 0, -1};bool inside(int x, int y) {return 0 <= x && x < H && 0 <= y && y < W;}int bfs() {queue<pair<int, int>> que;que.emplace(sx, sy);vector<vector<int>> d(H, vector<int>(W, inf));d[sx][sy] = 0;while (!que.empty()) {int x, y;tie(x, y) = que.front(); que.pop();if (x == gx && y == gy)break;rep(k, 4) {int nx = x + dx[k], ny = y + dy[k];int nnx = x + 2 * dx[k], nny = y + 2 * dy[k];if (inside(nx, ny) && d[nx][ny] == inf && abs(s[nx][ny] - s[x][y]) <= 1) {d[nx][ny] = d[x][y] + 1;que.emplace(nx, ny);}if (inside(nnx, nny) && d[nnx][nny] == inf && s[nnx][nny] == s[x][y] && s[nx][ny] < s[x][y]) {d[nnx][nny] = d[x][y] + 1;que.emplace(nnx, nny);}}}return (d[gx][gy] == inf ? -1 : d[gx][gy]);}signed main() {std::ios::sync_with_stdio(false);std::cin.tie(0);cin >> H >> W;cin >> sx >> sy >> gx >> gy;sx--, sy--, gx--, gy--;s.resize(H);rep(i, H) cin >> s[i];cout << (bfs() != -1 ? "YES" : "NO") << endl;}