結果

問題 No.402 最も海から遠い場所
ユーザー koba-e964koba-e964
提出日時 2016-08-04 15:30:21
言語 Rust
(1.77.0)
結果
MLE  
実行時間 -
コード長 2,506 bytes
コンパイル時間 922 ms
コンパイル使用メモリ 159,744 KB
実行使用メモリ 815,872 KB
最終ジャッジ日時 2024-04-24 15:27:53
合計ジャッジ時間 6,671 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 0 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 0 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 0 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 8 ms
6,400 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 40 ms
25,472 KB
testcase_16 AC 56 ms
36,224 KB
testcase_17 AC 819 ms
443,392 KB
testcase_18 AC 1,307 ms
178,048 KB
testcase_19 MLE -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#[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((0, -1, i as i32));
        que.push_back((0, h, i as i32));
    }
    for j in 0 .. h {
        que.push_back((0, j as i32, -1));
        que.push_back((0, j as i32, w));
    }
    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 {
                        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);
}
0