結果
問題 | No.402 最も海から遠い場所 |
ユーザー |
|
提出日時 | 2022-12-24 02:05:53 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 406 ms / 3,000 ms |
コード長 | 2,054 bytes |
コンパイル時間 | 12,825 ms |
コンパイル使用メモリ | 402,592 KB |
実行使用メモリ | 90,132 KB |
最終ジャッジ日時 | 2024-11-18 05:05:14 |
合計ジャッジ時間 | 16,231 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
コンパイルメッセージ
warning: unused import: `arch::x86_64::_MM_GET_ROUNDING_MODE` --> src/main.rs:1:34 | 1 | use std::{collections::VecDeque, arch::x86_64::_MM_GET_ROUNDING_MODE}; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: use of deprecated function `std::arch::x86_64::_MM_GET_ROUNDING_MODE`: see `_mm_getcsr` documentation - use inline assembly instead --> src/main.rs:1:48 | 1 | use std::{collections::VecDeque, arch::x86_64::_MM_GET_ROUNDING_MODE}; | ^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(deprecated)]` on by default
ソースコード
use std::{collections::VecDeque, arch::x86_64::_MM_GET_ROUNDING_MODE}; const DX: [isize; 8] = [-1, -1, -1, 0, 0, 1, 1, 1]; const DY: [isize; 8] = [-1, 0, 1, -1, 1, -1, 0, 1]; const INF: u16 = 30000u16; fn main() { let mut hw = String::new(); std::io::stdin().read_line(&mut hw).ok(); let hw: Vec<usize> = hw.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let h = hw[0]; let w = hw[1]; let mut grid = Vec::with_capacity(h+2); grid.push(vec![0u16; w+2]); for _ in 0..h { let mut line = vec![INF; w+2]; line[0] = 0; line[w+1] = 0; let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp = temp.trim().chars().collect::<Vec<_>>(); for i in 0..w { if temp[i] == '.' { line[i+1] = 0; } } grid.push(line); } grid.push(vec![0u16; w+2]); let mut deque = VecDeque::new(); for i in 1..=h { for j in 1..=w { if grid[i][j] == 0 { continue; } for dir in 0..8 { let nx = i as isize + DX[dir]; let nx = nx as usize; let ny = j as isize + DY[dir]; let ny = ny as usize; if grid[nx][ny] == 0 { grid[i][j] = 1; deque.push_back((i, j)); break; } } } } while let Some((i, j)) = deque.pop_front() { let nval = grid[i][j] + 1; for dir in 0..8 { let nx = i as isize + DX[dir]; let nx = nx as usize; let ny = j as isize + DY[dir]; let ny = ny as usize; if grid[nx][ny] > nval { grid[nx][ny] = nval; deque.push_back((nx, ny)); } } } // for v in grid.iter() { eprintln!("{:?}", v.iter().map(|j| j.to_string()).collect::<Vec<_>>().join("")); } println!("{}", grid.iter().map(|v| v.iter().max().unwrap()).max().unwrap()); }