結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-08-06 11:07:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,378 bytes |
| コンパイル時間 | 898 ms |
| コンパイル使用メモリ | 89,184 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-18 13:51:57 |
| 合計ジャッジ時間 | 1,771 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 19 WA * 2 |
ソースコード
#include <iostream>
#include <vector>
#include <utility>
#include <set>
#include <list>
#include <cassert>
#include <queue>
#include <cmath>
using namespace std;
using ll = long long int;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define YES(n) std::cout << ((n) ? "YES" : "NO" ) << "\n";
#define Yes(n) std::cout << ((n) ? "Yes" : "No" ) << "\n";
#define ALL_INCLUDED_ENVIRONMENT
template <class T, class Alloc, template <class, class> class C> std::ostream& operator<<(std::ostream& o, const C<T, Alloc>& v) {
o << "{";
bool init = 1;
for (auto e : v) {
if (init) { init = 0; }
else { o << ", "; }
o << e;
}
o << "}";
return o;
}
template <class X, class Y> std::ostream& operator<<(std::ostream& o, const std::pair<X, Y>& p) {
o << "(" << p.first << ", " << p.second << ")";
return o;
}
const ll INF = 0xffffffff;
ll h, w, sx, sy, gx, gy;
vector<vector<ll> > bs;
queue<pair<ll, ll>> que;
vector<vector<ll> > dists;
void step(ll x, ll y, ll newx, ll newy, ll newdist) {
if (newx >= 0 && newx < h && newy >= 0 && newy < w
&& abs(bs[x][y] - bs[newx][newy]) <= 1
&& dists[newx][newy] == INF) {
dists[newx][newy] = newdist;
que.push(make_pair(newx, newy));
}
}
void jump(ll x, ll y, ll newx, ll newy, ll newdist) {
if (newx >= 0 && newx < h && newy >= 0 && newy < w
&& bs[x][y] == bs[newx][newy]
&& dists[newx][newy] == INF) {
dists[newx][newy] = newdist;
que.push(make_pair(newx, newy));
}
}
int main() {
// cin.tie(0);
// ios::sync_with_stdio(false);
cin >> h >> w >> sx >> sy >> gx >> gy; cin.ignore();
sx--; sy--; gx--; gy--;
bs = vector<vector<ll> >(h, vector<ll>(w, 0));
dists = vector<vector<ll> >(h, vector<ll>(w, INF));
dists[sx][sy] = 0;
que.push(make_pair(sx, sy));
string line;
REP (i, h) {
getline(cin, line);
REP (j, w) {
assert('0' <= line[j] && line[j] <= '9');
bs[i][j] = line[j]-'0';
}
}
while (!que.empty()) {
pair<ll, ll> node = que.front();
ll x = node.first;
ll y = node.second;
ll d = dists[x][y];
que.pop();
step(x, y, x-1, y, d+1);
step(x, y, x+1, y, d+1);
step(x, y, x, y-1, d+1);
step(x, y, x, y+1, d+1);
jump(x, y, x-2, y, d+1);
jump(x, y, x+2, y, d+1);
jump(x, y, x, y-2, d+1);
jump(x, y, x, y+2, d+1);
}
YES(!(dists[gx][gy] == INF));
return 0;
}