結果

問題 No.424 立体迷路
ユーザー snrnsidy
提出日時 2021-03-05 07:45:09
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,804 bytes
コンパイル時間 1,015 ms
コンパイル使用メモリ 125,064 KB
最終ジャッジ日時 2025-01-19 10:19:16
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <unordered_map>
#include <memory.h>
#include <unordered_set>
#include <fstream>
using namespace std;
int dy[4] = { -1,0,1,0 };
int dx[4] = { 0,1,0,-1 };
bool visited[51][51];
char board[51][51];
int sy, sx, gy, gx, h, w;
int main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
cin >> h >> w;
cin >> sy >> sx >> gy >> gx;
for (int i = 1; i <= h; i++)
{
for (int j = 1; j <= w; j++)
{
cin >> board[i][j];
}
}
memset(visited, false, sizeof(visited));
visited[sy][sx] = true;
queue <pair<int, int>> que;
que.push({ sy,sx });
while (!que.empty())
{
int y = que.front().first;
int x = que.front().second;
que.pop();
for (int i = 0; i < 4; i++)
{
int ny = y + dy[i];
int nx = x + dx[i];
if (ny <= 0 || ny > h || nx <= 0 || nx > w)
{
continue;
}
if (abs(board[ny][nx] - board[y][x]) <= 1)
{
if (visited[ny][nx] == false)
{
visited[ny][nx] = true;
que.push({ ny,nx });
}
}
}
for (int i = 0; i < 4; i++)
{
int ny = y + 2*dy[i];
int nx = x + 2*dx[i];
if (ny <= 0 || ny > h || nx <= 0 || nx > w)
{
continue;
}
int my = (ny + y) / 2;
int mx = (nx + x) / 2;
if (board[my][mx]<=board[y][x] && board[y][x]==board[ny][nx])
{
if (visited[ny][nx] == false)
{
visited[ny][nx] = true;
que.push({ ny,nx });
}
}
}
}
if (visited[gy][gx])
{
cout << "YES" << '\n';
}
else
{
cout << "NO" << '\n';
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0