結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
peroon
|
| 提出日時 | 2019-05-13 17:54:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 2,625 bytes |
| コンパイル時間 | 1,365 ms |
| コンパイル使用メモリ | 174,180 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-05 07:18:17 |
| 合計ジャッジ時間 | 2,075 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 21 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:107:36: warning: 'nh' may be used uninitialized [-Wmaybe-uninitialized]
107 | if(h==height2 && nh<h){
| ~~^~
main.cpp:90:16: note: 'nh' was declared here
90 | ll nh;
| ^~
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")
const ll mod = 1e9 + 7;
const ll inf = 1e18;
template < typename T >
void vprint(T &V){
for(auto v : V){
cout << v << " ";
}
cout << endl;
}
struct Point{
ll x;
ll y;
Point(ll x, ll y): x(x), y(y) {}
};
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
ll d[100][100];
ll H, W;
bool in_range(ll x, ll y){
if(0<=x && x<W && 0<=y && y<H){
return true;
}else{
return false;
}
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// input
cin >> H >> W;
ll sx, sy, gx, gy;
// cin >> sx >> sy >> gx >> gy;
cin >> sy >> sx >> gy >> gx;
sx--;
sy--;
gx--;
gy--;
vector<string> G(H);
FOR(i, 0, H){
cin >> G.at(i);
}
FOR(i, 0, 100){
FOR(j, 0, 100){
d[i][j] = inf;
}
}
queue<Point> que;
que.push(Point(sx, sy));
d[sy][sx] = 0;
while(!que.empty()){
auto p = que.front();
que.pop();
ll h = G[p.y][p.x] - '0';
FOR(i, 0, 4){
ll nx = p.x + dx[i];
ll ny = p.y + dy[i];
ll nh;
if(in_range(nx, ny) && d[ny][nx]==inf){
nh = G[ny][nx] - '0';
ll diff = abs(nh - h);
if(diff<=1){
// 行ける
que.push(Point(nx, ny));
d[ny][nx] = d[p.y][p.x] + 1;
}
}
// はしご
nx += dx[i];
ny += dy[i];
if(in_range(nx, ny) && d[ny][nx]==inf){
ll height2 = G[ny][nx] - '0';
if(h==height2 && nh<h){
// わたせる
que.push(Point(nx, ny));
d[ny][nx] = d[p.y][p.x] + 1;
}
}
}
}
// p("distance");
// FOR(i, 0, H){
// FOR(j, 0, W){
// cout << d[i][j] << " ";
// }
// cout << endl;
// }
if(d[gy][gx]==inf){
p_no();
}else{
p_yes();
}
return 0;
}
peroon