結果

問題 No.1638 Robot Maze
ユーザー phsplsphspls
提出日時 2022-10-23 20:18:43
言語 Rust
(1.77.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,099 bytes
コンパイル時間 8,501 ms
コンパイル使用メモリ 153,856 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-15 05:46:10
合計ジャッジ時間 10,834 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,332 KB
testcase_01 AC 1 ms
4,360 KB
testcase_02 AC 1 ms
4,360 KB
testcase_03 AC 1 ms
4,360 KB
testcase_04 AC 1 ms
4,360 KB
testcase_05 AC 1 ms
4,360 KB
testcase_06 AC 1 ms
4,356 KB
testcase_07 AC 1 ms
4,356 KB
testcase_08 AC 1 ms
4,360 KB
testcase_09 AC 1 ms
4,360 KB
testcase_10 AC 1 ms
4,356 KB
testcase_11 AC 1 ms
4,356 KB
testcase_12 AC 1 ms
4,360 KB
testcase_13 AC 1 ms
4,364 KB
testcase_14 AC 2 ms
4,356 KB
testcase_15 AC 1 ms
4,356 KB
testcase_16 AC 1 ms
4,356 KB
testcase_17 AC 1 ms
4,356 KB
testcase_18 AC 1 ms
4,356 KB
testcase_19 AC 1 ms
4,356 KB
testcase_20 AC 1 ms
4,360 KB
testcase_21 AC 1 ms
4,360 KB
testcase_22 AC 2 ms
4,360 KB
testcase_23 AC 2 ms
4,356 KB
testcase_24 AC 1 ms
4,360 KB
testcase_25 AC 2 ms
4,356 KB
testcase_26 AC 1 ms
4,360 KB
testcase_27 AC 2 ms
4,356 KB
testcase_28 AC 1 ms
4,360 KB
testcase_29 AC 1 ms
4,356 KB
testcase_30 AC 1 ms
4,360 KB
testcase_31 AC 1 ms
4,356 KB
testcase_32 AC 2 ms
4,360 KB
testcase_33 AC 2 ms
4,360 KB
testcase_34 AC 2 ms
4,384 KB
testcase_35 AC 2 ms
4,360 KB
testcase_36 AC 2 ms
4,360 KB
testcase_37 AC 2 ms
4,356 KB
testcase_38 AC 2 ms
4,364 KB
testcase_39 AC 2 ms
4,360 KB
testcase_40 AC 2 ms
4,356 KB
testcase_41 AC 2 ms
4,356 KB
testcase_42 AC 2 ms
4,356 KB
testcase_43 AC 2 ms
4,356 KB
testcase_44 AC 2 ms
4,364 KB
testcase_45 AC 2 ms
4,360 KB
testcase_46 AC 2 ms
4,360 KB
testcase_47 AC 2 ms
4,356 KB
testcase_48 AC 2 ms
4,360 KB
testcase_49 AC 2 ms
4,360 KB
testcase_50 AC 2 ms
4,360 KB
testcase_51 AC 2 ms
4,360 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `VecDeque`
 --> Main.rs:1:25
  |
1 | use std::{collections::{VecDeque, BinaryHeap}, cmp::Reverse};
  |                         ^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: 1 warning emitted

ソースコード

diff #

use std::{collections::{VecDeque, BinaryHeap}, cmp::Reverse};

const INF: usize = 1usize << 60;
const DX: [isize; 4] = [-1, 1, 0, 0];
const DY: [isize; 4] = [0, 0, 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 costs = [temp[0], temp[1], temp[2], temp[3]];
    let k = temp[4];
    let p = temp[5];
    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();
            let temp = temp.trim();
            temp.chars().collect::<Vec<_>>()
        })
        .collect::<Vec<_>>();

    let mut dp = vec![vec![INF; w]; h];
    dp[sx][sy] = 0;
    let mut pque = BinaryHeap::new();
    pque.push((Reverse(0), sx, sy));
    while let Some((Reverse(cost), x, y)) = pque.pop() {
        if dp[x][y] < cost { continue; }
        for dir in 0..4 {
            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 grid[nx][ny] == '#' { continue; }
                let ncost = cost + costs[dir] + if grid[nx][ny] == '@' { p } else { 0 };
                if dp[nx][ny] <= ncost { continue; }
                dp[nx][ny] = ncost;
                pque.push((Reverse(ncost), nx, ny));
            }
        }
    }
    if dp[gx][gy] > k {
        println!("No");
    } else {
        println!("Yes");
    }
}
0