結果

問題 No.424 立体迷路
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2019-04-30 01:23:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,772 bytes
コンパイル時間 652 ms
コンパイル使用メモリ 72,072 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 17:06:46
合計ジャッジ時間 1,695 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <set>
#include <cstdio>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define P pair<int, int>

#define MOD 1000000007
#define INF 1012345678
#define NINF (-2147483647-1)
#define LLINF 9223372036854775807
using ll = long long;
using namespace std;

int h, w;
int b[51][51];
bool visited[51][51];
int dx[] = {1,0,-1, 0};
int dy[] = {0,1, 0,-1};
int dx2[] = {2,0,-2, 0};
int dy2[] = {0,2, 0,-2};

void dfs(int x,int y) {
    visited[x][y] = true;
    for (int i = 0; i < 4; i++)
    {
        if (x + dx[i] < h && x + dx[i] >= 0 &&
            y + dy[i] < w && y + dy[i] >= 0 &&
            abs(b[x][y] - b[x + dx[i]][y + dy[i]]) <= 1 &&
            !visited[x + dx[i]][y + dy[i]]) {
            dfs(x + dx[i], y + dy[i]);
        }
    }
    for (int i = 0; i < 4; i++)
    {
        if (x + dx2[i] < h && x + dx2[i] >= 0 &&
            y + dy2[i] < w && y + dy2[i] >= 0 &&
            b[x][y] == b[x + dx2[i]][y + dy2[i]] &&
            b[x][y] > b[x + dx[i]][y + dy[i]] &&
            !visited[x + dx2[i]][y + dy2[i]]) {
            dfs(x + dx2[i], y + dy2[i]);
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int sx, sy, gx, gy;
    cin >> h >> w;
    cin >> sx >> sy >> gx >> gy;
    sx--; sy--; gx--; gy--;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            char c;
            cin >> c;
            b[i][j] = c - '0';
        }
    }
    dfs(sx, sy);
    if (visited[gx][gy]) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    getchar(); getchar();
}
0