結果
問題 | No.867 避難経路 |
ユーザー | koba-e964 |
提出日時 | 2021-10-28 23:32:32 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 2,924 ms / 6,000 ms |
コード長 | 3,063 bytes |
コンパイル時間 | 15,997 ms |
コンパイル使用メモリ | 387,516 KB |
実行使用メモリ | 72,232 KB |
最終ジャッジ日時 | 2024-10-07 08:26:26 |
合計ジャッジ時間 | 77,426 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
6,820 KB |
testcase_01 | AC | 4 ms
6,820 KB |
testcase_02 | AC | 3 ms
6,816 KB |
testcase_03 | AC | 4 ms
6,816 KB |
testcase_04 | AC | 4 ms
6,816 KB |
testcase_05 | AC | 4 ms
6,816 KB |
testcase_06 | AC | 4 ms
6,820 KB |
testcase_07 | AC | 4 ms
6,816 KB |
testcase_08 | AC | 3 ms
6,816 KB |
testcase_09 | AC | 3 ms
6,820 KB |
testcase_10 | AC | 4 ms
6,820 KB |
testcase_11 | AC | 4 ms
6,816 KB |
testcase_12 | AC | 4 ms
6,820 KB |
testcase_13 | AC | 4 ms
6,816 KB |
testcase_14 | AC | 4 ms
6,816 KB |
testcase_15 | AC | 2,254 ms
72,060 KB |
testcase_16 | AC | 2,135 ms
72,152 KB |
testcase_17 | AC | 2,395 ms
72,000 KB |
testcase_18 | AC | 2,139 ms
72,060 KB |
testcase_19 | AC | 2,099 ms
72,136 KB |
testcase_20 | AC | 2,053 ms
72,076 KB |
testcase_21 | AC | 1,980 ms
72,016 KB |
testcase_22 | AC | 2,081 ms
72,112 KB |
testcase_23 | AC | 2,337 ms
72,072 KB |
testcase_24 | AC | 1,998 ms
72,016 KB |
testcase_25 | AC | 2,076 ms
72,076 KB |
testcase_26 | AC | 2,086 ms
72,028 KB |
testcase_27 | AC | 2,148 ms
72,092 KB |
testcase_28 | AC | 2,640 ms
72,076 KB |
testcase_29 | AC | 2,924 ms
72,232 KB |
testcase_30 | AC | 1,780 ms
72,100 KB |
testcase_31 | AC | 2,081 ms
71,924 KB |
testcase_32 | AC | 1,999 ms
72,080 KB |
testcase_33 | AC | 1,955 ms
72,172 KB |
testcase_34 | AC | 1,915 ms
71,872 KB |
testcase_35 | AC | 2,117 ms
71,776 KB |
testcase_36 | AC | 2,135 ms
71,388 KB |
testcase_37 | AC | 1,937 ms
68,168 KB |
testcase_38 | AC | 1,926 ms
68,020 KB |
testcase_39 | AC | 1,901 ms
68,196 KB |
testcase_40 | AC | 1,867 ms
68,168 KB |
testcase_41 | AC | 1 ms
6,820 KB |
testcase_42 | AC | 2 ms
6,820 KB |
testcase_43 | AC | 2 ms
6,816 KB |
ソースコード
use std::cmp::*; 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, usize1) => (read_value!($next, usize) - 1); ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); } 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: i32 = 1 << 30; let mut que = BinaryHeap::new(); que.push((Reverse(0), gx, gy)); let mut dist = vec![vec![INF; 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; } let nd = d + k + a[nx][ny]; if dist[nx][ny] > nd { if dist[nx][ny] < nd - 1 { dist[nx][ny] = nd - 1; } que.push((Reverse(nd), 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 = 231; 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 div = (KLIM - 1) as i32 * (KLIM - 1) as i32; let q = tmp / div; let r = tmp % div; d = q as i64 * k * k + r as i64; } else { d = dist[k as usize][x][y] as i64; } puts!("{}\n", d + k * k + a[gx][gy] as i64); } }