結果

問題 No.424 立体迷路
ユーザー ふーらくたるふーらくたる
提出日時 2016-09-22 22:49:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,556 bytes
コンパイル時間 491 ms
コンパイル使用メモリ 65,548 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 16:46:25
合計ジャッジ時間 1,540 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <queue>
#include <utility>
using namespace std;

using P = pair<int, int>;

const int MAX_H = 60;
const int MAX_W = 60;

int dx[4] = {1, 0, -1, 0},
    dy[4] = {0, 1, 0, -1};

string b[MAX_H];

bool visited[MAX_H][MAX_W];
int h, w, sx, sy, gx, gy;

bool inside(int x, int y) {
    return 0 <= x && x < h && 0 <= y && y < w;
}

int main() {
    cin >> h >> w;
    cin >> sx >> sy >> gx >> gy;
    sx--; sy--;
    gx--; gy--;

    for (int i = 0; i < h; i++) {
        cin >> b[i];
    }


    queue<P> que;
    que.push(P(sx, sy));
    visited[sx][sy] = true;
    while (!que.empty()) {
        P p = que.front(); que.pop();
        if (p.first == gx && p.second == gy) {
            cout << "YES" << endl;
            return 0;
        }
        int x = p.first,
            y = p.second;
        for (int i = 0; i < 4; i++) {
            for (int d = 1; d <= 2; d++) {
                int nx = x + dx[i] * d,
                    ny = y + dy[i] * d;
                if (!inside(nx, ny) || visited[nx][ny]) continue;

                if (d == 1 && abs((b[x][y] - '0') - (b[nx][ny] - '0')) <= 1) {
                    que.push(P(nx, ny));
                    visited[nx][ny] = true;
                }
                if (d == 2 && abs((b[x][y] - '0') - (b[nx][ny] - '0')) == 0
                        && b[x][y] - '0' > b[x + dx[i]][y + dy[i]] - '0') {
                    que.push(P(nx, ny));
                    visited[nx][ny] = true;
                }
            }
        }
    }
    cout << "NO" << endl;

    return 0;
}
0