結果

問題 No.1638 Robot Maze
ユーザー StrorkisStrorkis
提出日時 2021-08-06 22:49:48
言語 Rust
(1.77.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 2,831 bytes
コンパイル時間 1,330 ms
コンパイル使用メモリ 181,176 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 04:19:11
合計ジャッジ時間 2,960 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 5 ms
4,348 KB
testcase_34 AC 3 ms
4,348 KB
testcase_35 AC 3 ms
4,348 KB
testcase_36 AC 3 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 3 ms
4,348 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 4 ms
4,348 KB
testcase_42 AC 4 ms
4,348 KB
testcase_43 AC 1 ms
4,348 KB
testcase_44 AC 2 ms
4,348 KB
testcase_45 AC 2 ms
4,348 KB
testcase_46 AC 2 ms
4,348 KB
testcase_47 AC 2 ms
4,348 KB
testcase_48 AC 3 ms
4,348 KB
testcase_49 AC 1 ms
4,348 KB
testcase_50 AC 4 ms
4,348 KB
testcase_51 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

pub mod io {
    use std::io::{BufRead, ErrorKind};

    pub fn scan<R: BufRead>(r: &mut R) -> Vec<u8> {
        let mut res = Vec::new();
        loop {
            let buf = match r.fill_buf() {
                Ok(buf) => buf,
                Err(e) if e.kind() == ErrorKind::Interrupted => continue,
                Err(e) => panic!("{}", e), 
            };
            let (done, used, buf) = {
                match buf.iter().position(u8::is_ascii_whitespace) {
                    Some(i) => (i > 0 || res.len() > 0, i + 1, &buf[..i]),
                    None => (buf.is_empty(), buf.len(), buf),
                }
            };
            res.extend_from_slice(buf);
            r.consume(used);
            if done { return res; }
        }
    }

    #[macro_export]
    macro_rules! scan {
        ($r:expr, [$t:tt; $n:expr]) => {
            (0..$n).map(|_| scan!($r, $t)).collect::<Vec<_>>()
        };
        ($r:expr, [$t:tt]) => {
            scan!($r, [$t; scan!($r, usize)])
        };
        ($r:expr, ($($t:tt),*)) => {
            ($(scan!($r, $t)),*)
        };
        ($r:expr, Usize1) => {
            scan!($r, usize) - 1
        };
        ($r:expr, Bytes) => {
            io::scan($r)
        };
        ($r:expr, String) => {
            String::from_utf8(scan!($r, Bytes)).unwrap()
        };
        ($r:expr, $t:ty) => {
            scan!($r, String).parse::<$t>().unwrap()
        };
    }

    #[macro_export]
    macro_rules! input {
        ($($($v:ident)* : $t:tt),* $(,)?) => {
            let stdin = std::io::stdin();
            let ref mut reader = std::io::BufReader::new(stdin.lock());
            $(let $($v)* = scan!(reader, $t);)*
        };
    }
}

use std::collections::VecDeque;

const INF: u64 = 1 << 60;

fn main() {
    input! {
        h: usize, w: usize,
        u: u64, d: u64, r: u64, l: u64, k: u64, p: u64,
        x_s: Usize1, y_s: Usize1, x_t: Usize1, y_t: Usize1,
        c: [Bytes; h],
    }

    let mut queue = VecDeque::new();
    queue.push_back((x_s, y_s, 0));
    let mut dist = vec![vec![INF; w]; h];
    dist[x_s][y_s] = 0;
    while let Some((x, y, now_cost)) = queue.pop_front() {
        if dist[x][y] < now_cost {
            continue;
        }
        for &(dx, dy, cost) in &[(!0, 0, u), (1, 0, d), (0, 1, r), (0, !0, l)] {
            let (nx, ny) = (x.wrapping_add(dx), y.wrapping_add(dy));
            if nx >= h || ny >= w || c[nx][ny] == b'#' {
                continue;
            }
            let next_cost = now_cost + if c[nx][ny] == b'@' { cost + p } else { cost };
            if next_cost < dist[nx][ny] {
                dist[nx][ny] = next_cost;
                queue.push_back((nx, ny, next_cost));
            }
        }
    }

    if dist[x_t][y_t] <= k {
        println!("Yes");
    } else {
        println!("No");
    }
}
0