結果
問題 | No.424 立体迷路 |
ユーザー |
|
提出日時 | 2020-10-10 17:54:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,543 bytes |
コンパイル時間 | 1,000 ms |
コンパイル使用メモリ | 88,576 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 16:05:22 |
合計ジャッジ時間 | 1,707 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
#include<iostream>#include<vector>#include<string>#include<cmath>#include<queue>using namespace std;typedef pair<int,int> P;int h,w;int sx,sy,gx,gy;vector<vector<int>> b(55,vector<int>(55,-1));vector<vector<bool>> used(55,vector<bool>(55,false));const int dx[] = {1,0,-1,0};const int dy[] = {0,1,0,-1};const int dx2[] = {2,0,-2,0};const int dy2[] = {0,2,0,-2};bool bfs(){queue<P> que;que.push(P(sx,sy));used[sx][sy] = true;while(!que.empty()){P cur = que.front();que.pop();if(cur.first == gx && cur.second == gy){return true;}for(int i=0;i < 4;i++){int nx = cur.first + dx[i],ny = cur.second + dy[i];int nx2 = cur.first + dx2[i],ny2 = cur.second + dy2[i];if(nx > 0 && nx <= h && ny > 0 && ny <= w){int height = b[nx][ny] - b[cur.first][cur.second];int height2 = b[nx2][ny2] - b[cur.first][cur.second];if(height == 0 || height == 1 || height == -1){if(!used[nx][ny]) que.push(P(nx,ny));used[nx][ny] = true;}else if(height <= -1 && height2 == 0){if(!used[nx2][ny2]) que.push(P(nx2,ny2));used[nx2][ny2] = true;}}}}return false;}int main(){cin >> h >> w;cin >> sx >> sy >> gx >> gy;for(int i=1;i <= h;i++){string s;cin >> s;for(int j=1;j <= w;j++){b[i][j] = s[j-1] - '0';}}if(bfs()) cout << "YES" << endl;else cout << "NO" << endl;return 0;}