結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-11-24 00:37:11 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,246 bytes |
| コンパイル時間 | 2,001 ms |
| コンパイル使用メモリ | 179,276 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-27 10:27:23 |
| 合計ジャッジ時間 | 2,599 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 19 WA * 2 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int in_range( int h, int w, int x, int y ){
return 0 <= x and x < h and 0 <= y and y < w;
}
signed main(){
int H, W; cin >> H >> W;
int Sx, Sy, Gx, Gy; cin >> Sx >> Sy >> Gx >> Gy; --Sx, --Sy, --Gx, --Gy;
vector< string > G( H );
for( int i = 0; i < H; ++i )
cin >> G[ i ];
vector< vector< int > > vis( H, vector< int >( W ) );
queue< pair< int, int > > que;
que.emplace( Sx, Sy );
vis[ Sx ][ Sy ] = 1;
while( not que.empty() ){
int x, y; tie( x, y ) = que.front(); que.pop();
if( tie( x, y ) == tie( Gx, Gy ) )
cout << "YES" << endl, exit( 0 );
static const int dx[] = { 0, 1, 0, -1 };
static const int dy[] = { 1, 0, -1, 0 };
for( int di = 0; di < 4; ++di ){
int nx = x + dx[ di ], ny = y + dy[ di ];
if( not in_range( H, W, nx, ny ) ) continue;
if( not vis[ nx ][ ny ] and abs( G[ nx ][ ny ] - G[ x ][ y ] ) <= 1 )
vis[ nx ][ ny ] = 1, que.emplace( nx, ny );
nx += dx[ di ], ny += dy[ di ];
if( not in_range( H, W, nx, ny ) ) continue;
if( not vis[ nx ][ ny ] and G[ nx ][ ny ] == G[ x ][ y ] )
vis[ nx ][ ny ] = 1, que.emplace( nx, ny );
}
}
cout << "NO" << endl;
return 0;
}