結果
問題 | No.402 最も海から遠い場所 |
ユーザー | koba-e964 |
提出日時 | 2016-08-04 16:11:54 |
言語 | Rust (1.77.0 + proconio) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,628 bytes |
コンパイル時間 | 26,399 ms |
コンパイル使用メモリ | 377,644 KB |
実行使用メモリ | 816,640 KB |
最終ジャッジ日時 | 2024-11-07 00:01:53 |
合計ジャッジ時間 | 25,800 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 1 ms
5,248 KB |
testcase_05 | AC | 1 ms
5,248 KB |
testcase_06 | AC | 1 ms
5,248 KB |
testcase_07 | AC | 1 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 1 ms
5,248 KB |
testcase_10 | AC | 1 ms
5,248 KB |
testcase_11 | AC | 1 ms
5,248 KB |
testcase_12 | AC | 2 ms
5,248 KB |
testcase_13 | AC | 9 ms
6,528 KB |
testcase_14 | AC | 5 ms
5,248 KB |
testcase_15 | AC | 40 ms
25,472 KB |
testcase_16 | AC | 51 ms
36,352 KB |
testcase_17 | AC | 562 ms
239,744 KB |
testcase_18 | AC | 1,239 ms
178,048 KB |
testcase_19 | MLE | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
ソースコード
#[allow(unused_imports)] use std::cmp::*; #[allow(unused_imports)] use std::collections::*; use std::io::*; #[allow(dead_code)] fn getline() -> String { let mut ret = String::new(); std::io::stdin().read_line(&mut ret).ok(); return ret; } fn get_word() -> String { let mut stdin = std::io::stdin(); let mut u8b: [u8; 1] = [0]; loop { let mut buf: Vec<u8> = Vec::with_capacity(16); loop { let res = stdin.read(&mut u8b); if res.is_err() || res.ok().unwrap() == 0 || u8b[0] <= ' ' as u8 { break; } else { buf.push(u8b[0]); } } if buf.len() >= 1 { let ret = std::string::String::from_utf8(buf).unwrap(); return ret; } } } fn parse<T: std::str::FromStr>(s: &str) -> T { s.parse::<T>().ok().unwrap() } #[allow(dead_code)] fn get<T: std::str::FromStr>() -> T { parse(&get_word()) } fn main() { let h: i32 = get(); let w: i32 = get(); let s: Vec<Vec<char>> = (0 .. h).map(|_| get_word().chars().collect()).collect(); let mut que: VecDeque<(i32, i32, i32)> = VecDeque::with_capacity(((h + 2) * (w + 2)) as usize); let mut dp: Vec<Vec<i32>> = (0 .. h).map(|_| vec![100_000; w as usize]).collect(); for i in 0 .. w { que.push_back((1, 0, i as i32)); que.push_back((1, h - 1, i as i32)); } for j in 0 .. h { que.push_back((1, j as i32, 0)); que.push_back((1, j as i32, w - 1)); } for i in 0 .. h { for j in 0 .. w { if s[i as usize][j as usize] == '.' { que.push_back((0, i, j)); } } } while let Some((cost, x, y)) = que.pop_front() { if !(x >= 0 && x < h && y >= 0 && y < w) || cost < dp[x as usize][y as usize] { if x >= 0 && x < h && y >= 0 && y < w { dp[x as usize][y as usize] = cost; } for dx in -1 .. 2 { for dy in -1 .. 2 { if dx * dx + dy * dy == 0 { continue; } let nx = x + dx; let ny = y + dy; if nx < 0 || nx >= h || ny < 0 || ny >= w { continue; } que.push_back((cost + 1, nx, ny)); } } } } let mut ma: i32 = 0; for i in 0 .. h { ma = max(ma, *dp[i as usize].iter().max().unwrap()); } println!("{}", ma); }