結果

問題 No.424 立体迷路
ユーザー phspls
提出日時 2022-12-02 00:17:35
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 1,786 bytes
コンパイル時間 17,461 ms
コンパイル使用メモリ 379,044 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-09 05:30:25
合計ジャッジ時間 14,208 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4 WA * 1
other AC * 19 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::VecDeque;

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

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..12 {
            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 && grid[x][y] != grid[nx][ny] { continue; }
                checked[nx][ny] = true;
                deque.push_back((nx, ny));
            }
        }
    }
    if checked[gx][gy] {
        println!("YES");
    } else {
        println!("NO");
    }
}
0