結果

問題 No.208 王将
ユーザー sinosino
提出日時 2020-04-14 12:08:19
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,613 bytes
コンパイル時間 1,370 ms
コンパイル使用メモリ 183,316 KB
実行使用メモリ 13,760 KB
最終ジャッジ日時 2024-04-09 05:16:30
合計ジャッジ時間 4,385 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::collections::HashMap;
use std::collections::HashSet;

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_end().to_owned()
}


fn main() {
    let dist = read!(i32, i32);
    let obst = read!(i32, i32);
    let ops = [(-1i32, -1i32), (-1, 0), (-1, 1), (0, 1), (0, -1), (1, -1), (1, 0), (1, 1)];

    let mut open = vec![((0i32, 0i32), 0, obst.0.max(obst.1))];

    let mut close = HashSet::new();
    close.insert((0i32, 0i32));

    while let Some((coord, g, _)) = open.pop() {
        if coord.0 == dist.0 && coord.1 == dist.1 {
            println!("{}", g);
            return;
        }
        for op in ops.iter() {
            let new_coord = (op.0 + coord.0, op.1 + coord.1);
            if close.insert(new_coord) {
                open.push((new_coord, g + 1, (new_coord.0 - dist.0).abs().max((new_coord.1-dist.1).abs())));
            }
        }
        open.sort_by_key(|(_, g, h)| std::cmp::Reverse(g+h));
    }
}

0