結果

問題 No.340 雪の足跡
ユーザー koba-e964koba-e964
提出日時 2021-11-17 23:54:27
言語 Rust
(1.77.0)
結果
MLE  
実行時間 -
コード長 2,508 bytes
コンパイル時間 1,946 ms
コンパイル使用メモリ 158,636 KB
実行使用メモリ 812,704 KB
最終ジャッジ日時 2023-08-25 21:03:11
合計ジャッジ時間 10,783 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 6 ms
4,380 KB
testcase_12 AC 5 ms
4,380 KB
testcase_13 AC 9 ms
4,640 KB
testcase_14 AC 413 ms
103,572 KB
testcase_15 AC 641 ms
146,852 KB
testcase_16 AC 254 ms
80,124 KB
testcase_17 AC 928 ms
202,744 KB
testcase_18 AC 663 ms
158,692 KB
testcase_19 AC 901 ms
202,272 KB
testcase_20 MLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::*;
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
    input! {
        w: usize, h: usize, n: usize,
        b: [([usize], usize); n],
    }
    let mut g = vec![vec![]; h * w];
    for (mut b, blast) in b {
        b.push(blast);
        let m = b.len();
        for i in 0..m - 1 {
            let (x, y) = if b[i] < b[i + 1] {
                (b[i], b[i + 1])
            } else {
                (b[i + 1], b[i])
            };
            if x % w == y % w {
                for i in 0..y / w - x / w {
                    g[x + i * w].push(x + i * w + w);
                    g[x + i * w + w].push(x + i * w);
                }
            } else {
                for i in x..y {
                    g[i].push(i + 1);
                    g[i + 1].push(i);
                }
            }
        }
    }
    for i in 0..h * w {
        g[i].sort_unstable(); g[i].dedup();
    }
    let mut que = VecDeque::new();
    const INF: i32 = 1 << 28;
    let mut dist = vec![INF; h * w];
    que.push_back((0, 0));
    while let Some((d, v)) = que.pop_front() {
        if dist[v] <= d { continue; }
        dist[v] = d;
        for &w in &g[v] {
            if dist[w] > d + 1 {
                que.push_back((d + 1, w));
            }
        }
    }
    if dist[h * w - 1] >= INF {
        println!("Odekakedekinai..");
    } else {
        println!("{}", dist[h * w - 1]);
    }
}
0