結果

問題 No.424 立体迷路
ユーザー phsplsphspls
提出日時 2022-12-02 00:23:10
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,944 bytes
コンパイル時間 1,103 ms
コンパイル使用メモリ 161,408 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 11:28:54
合計ジャッジ時間 1,742 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

use std::collections::VecDeque;

const DX: [isize; 8] = [-1, 1, 0, 0, -2, 2, 0, 0];
const DY: [isize; 8] = [0, 0, -1, 1, 0, 0, -2, 2];

fn main() {
    let mut hw = String::new();
    std::io::stdin().read_line(&mut hw).ok();
    let hw: Vec<usize> = hw.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let h = hw[0];
    let w = hw[1];
    let mut temp = String::new();
    std::io::stdin().read_line(&mut temp).ok();
    let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let sx = temp[0]-1;
    let sy = temp[1]-1;
    let gx = temp[2]-1;
    let gy = temp[3]-1;
    let grid = (0..h).map(|_| {
            let mut temp = String::new();
            std::io::stdin().read_line(&mut temp).ok();
            temp.trim().chars().map(|c| c as isize - '0' as isize).collect::<Vec<_>>()
        })
        .collect::<Vec<_>>();

    let mut deque = VecDeque::new();
    deque.push_back((sx, sy));
    let mut checked = vec![vec![false; w]; h];
    checked[sx][sy] = true;
    while let Some((x, y)) = deque.pop_front() {
        for dir in 0..8 {
            let nx = x as isize + DX[dir];
            let ny = y as isize + DY[dir];
            if nx >= 0 && ny >= 0 && nx < h as isize && ny < w as isize {
                let nx = nx as usize;
                let ny = ny as usize;
                if checked[nx][ny] { continue; }
                if dir < 4 && (grid[x][y] - grid[nx][ny]).abs() > 1 { continue; }
                if dir >= 4 {
                    if grid[x][y] != grid[nx][ny] { continue; }
                    let mx = (x + nx) / 2;
                    let my = (y + ny) / 2;
                    if grid[mx][my] > grid[x][y] { continue; }
                }
                checked[nx][ny] = true;
                deque.push_back((nx, ny));
            }
        }
    }
    if checked[gx][gy] {
        println!("YES");
    } else {
        println!("NO");
    }
}
0