結果
問題 | No.867 避難経路 |
ユーザー | koba-e964 |
提出日時 | 2021-10-28 23:18:49 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,335 bytes |
コンパイル時間 | 13,074 ms |
コンパイル使用メモリ | 401,228 KB |
実行使用メモリ | 193,200 KB |
最終ジャッジ日時 | 2024-10-07 08:14:45 |
合計ジャッジ時間 | 27,139 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
コンパイルメッセージ
warning: constant `INF` is never used --> src/main.rs:55:11 | 55 | const INF: i64 = 1 << 30; | ^^^ | = note: `#[warn(dead_code)]` on by default
ソースコード
#[allow(unused_imports)] use std::cmp::*; #[allow(unused_imports)] use std::collections::*; use std::io::{Write, BufWriter}; // 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, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, usize1) => (read_value!($next, usize) - 1); ($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")); } trait Change { fn chmax(&mut self, x: Self); fn chmin(&mut self, x: Self); } impl<T: PartialOrd> Change for T { fn chmax(&mut self, x: T) { if *self < x { *self = x; } } fn chmin(&mut self, x: T) { if *self > x { *self = x; } } } fn find_dist(a: &[Vec<i32>], gx: usize, gy: usize, k: i32) -> Vec<Vec<i32>> { let n = a.len(); let m = a[0].len(); const INF: i64 = 1 << 30; let mut que = BinaryHeap::new(); que.push((Reverse(0), gx, gy)); let mut dist = vec![vec![0; m]; n]; let dxy = [(0i32, 1i32), (1, 0), (0, -1), (-1, 0)]; while let Some((Reverse(d), x, y)) = que.pop() { if dist[x][y] <= d { continue; } dist[x][y] = d; for &(dx, dy) in &dxy { let nx = (x as i32 + dx) as usize; let ny = (y as i32 + dy) as usize; if nx >= n || ny >= m { continue; } que.push((Reverse(d + k + a[nx][ny]), nx, ny)); } } dist } // Tags: exploit-small-constraints // In this problem K is essentially at most 710 fn main() { let out = std::io::stdout(); let mut out = BufWriter::new(out.lock()); macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););} const KLIM: usize = 711; input! { h: usize, w: usize, gx: usize1, gy: usize1, a: [[i32; w]; h], q: usize, xyk: [(usize1, usize1, i64); q], } let mut dist = vec![vec![]; KLIM]; for i in 0..KLIM { dist[i] = find_dist(&a, gx, gy, i as i32 * i as i32); } for (x, y, k) in xyk { let d; if k >= KLIM as i64 { let tmp = dist[KLIM - 1][x][y]; let q = tmp / (KLIM - 1) as i32; let r = tmp % (KLIM - 1) as i32; d = q as i64 * k * k + r as i64; } else { d = dist[k as usize][x][y] as i64; } puts!("{}\n", d); } }