提出 #16146255
ソースコード 拡げる
#![allow(
non_snake_case,
unused_variables,
unused_assignments,
unused_mut,
unused_imports,
dead_code,
unused_macros
)]
//use proconio::fastout;
use proconio::input;
use proconio::marker::*;
//use std::collections::HashSet;
use std::cmp::*;
use std::collections::*;
macro_rules! debug {
($($a:expr),* $(,)*) => {
#[cfg(debug_assertions)]
eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*);
};
}
fn main() {
input! {
H:usize,
W:usize,
C:(Usize1, Usize1),
D:(Usize1, Usize1),
S:[Chars;H]
}
let C: (usize, usize) = (C.0 + 2, C.1 + 2);
let D: (usize, usize) = (D.0 + 2, D.1 + 2);
let S: Vec<Vec<char>> = S;
let mut kabe = vec![vec![true; W + 10]; H + 10];
for x in 0..H {
for y in 0..W {
if S[x][y] == '.' {
kabe[x + 2][y + 2] = false;
}
}
}
let kabe: Vec<Vec<bool>> = kabe;
// Cを基準に幅優先探索。
// (n=ワープ回数, 位置)
let mut h = BinaryHeap::new();
//訪問済み
let mut v = vec![vec![false; W + 10]; H + 10];
// ワープ回数
let mut d = vec![vec![std::u64::MAX; W + 10]; H + 10];
v[C.0][C.1] = true;
d[C.0][C.1] = 0;
h.push((0, C.0, C.1));
while let Some((c, x, y)) = h.pop() {
toho(&kabe, &mut d, &mut h, c, x - 1, y);
toho(&kabe, &mut d, &mut h, c, x + 1, y);
toho(&kabe, &mut d, &mut h, c, x, y - 1);
toho(&kabe, &mut d, &mut h, c, x, y + 1);
warp(&kabe, &mut d, &mut h, c, x - 2, y - 2);
warp(&kabe, &mut d, &mut h, c, x - 2, y - 1);
warp(&kabe, &mut d, &mut h, c, x - 2, y);
warp(&kabe, &mut d, &mut h, c, x - 2, y + 1);
warp(&kabe, &mut d, &mut h, c, x - 2, y + 2);
warp(&kabe, &mut d, &mut h, c, x - 1, y - 2);
warp(&kabe, &mut d, &mut h, c, x - 1, y - 1);
warp(&kabe, &mut d, &mut h, c, x - 1, y + 1);
warp(&kabe, &mut d, &mut h, c, x - 1, y + 2);
warp(&kabe, &mut d, &mut h, c, x, y - 2);
warp(&kabe, &mut d, &mut h, c, x, y + 2);
warp(&kabe, &mut d, &mut h, c, x + 1, y - 2);
warp(&kabe, &mut d, &mut h, c, x + 1, y - 1);
warp(&kabe, &mut d, &mut h, c, x + 1, y + 1);
warp(&kabe, &mut d, &mut h, c, x + 1, y + 2);
warp(&kabe, &mut d, &mut h, c, x + 2, y - 2);
warp(&kabe, &mut d, &mut h, c, x + 2, y - 1);
warp(&kabe, &mut d, &mut h, c, x + 2, y);
warp(&kabe, &mut d, &mut h, c, x + 2, y + 1);
warp(&kabe, &mut d, &mut h, c, x + 2, y + 2);
}
let ans = d[D.0][D.1];
if ans < std::u64::MAX {
println!("{}", ans);
} else {
println!("-1");
}
}
fn warp(
kabe: &Vec<Vec<bool>>,
d: &mut Vec<Vec<u64>>,
h: &mut BinaryHeap<(u64, usize, usize)>,
c: u64,
x: usize,
y: usize,
) -> () {
if kabe[x][y] == false {
let c = c + 1;
if d[x][y] > c {
d[x][y] = c;
h.push((c, x, y));
}
}
}
fn toho(
kabe: &Vec<Vec<bool>>,
d: &mut Vec<Vec<u64>>,
h: &mut BinaryHeap<(u64, usize, usize)>,
c: u64,
x: usize,
y: usize,
) -> () {
if kabe[x][y] == false {
if d[x][y] > c {
d[x][y] = c;
h.push((c, x, y));
}
}
}
提出情報
提出日時 |
|
問題 |
D - Wizard in Maze |
ユーザ |
aoriso |
言語 |
Rust (1.42.0) |
得点 |
0 |
コード長 |
3052 Byte |
結果 |
TLE |
実行時間 |
2206 ms |
メモリ |
25460 KiB |
ジャッジ結果
セット名 |
Sample |
All |
得点 / 配点 |
0 / 0 |
0 / 400 |
結果 |
|
|
セット名 |
テストケース |
Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
All |
hand_01.txt, hand_02.txt, max_01.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_11.txt, random_12.txt, sample_01.txt, sample_02.txt, sample_03.txt |
ケース名 |
結果 |
実行時間 |
メモリ |
hand_01.txt |
AC |
8 ms |
2036 KiB |
hand_02.txt |
AC |
2 ms |
2168 KiB |
max_01.txt |
AC |
46 ms |
17168 KiB |
random_01.txt |
AC |
28 ms |
16832 KiB |
random_02.txt |
TLE |
2205 ms |
3796 KiB |
random_03.txt |
TLE |
2206 ms |
17744 KiB |
random_04.txt |
TLE |
2205 ms |
4708 KiB |
random_05.txt |
TLE |
2206 ms |
25460 KiB |
random_06.txt |
TLE |
2206 ms |
9384 KiB |
random_11.txt |
AC |
14 ms |
2444 KiB |
random_12.txt |
AC |
2 ms |
2196 KiB |
sample_01.txt |
AC |
2 ms |
2136 KiB |
sample_02.txt |
AC |
2 ms |
1948 KiB |
sample_03.txt |
AC |
2 ms |
1968 KiB |