Submission #60511999
Source Code Expand
use std::collections::VecDeque;
#[allow(unused_imports)]
use itertools::iproduct;
use proconio::{input, marker::Chars};
fn main() {
input!{
h: usize,
w: usize,
d: u64,
s: [Chars; h],
}
let inf = 1u64 << 60;
let mut seen = vec![vec![inf; w]; h];
let mut que = VecDeque::new();
for (i, j) in iproduct!(0..h, 0..w) {
if s[i][j] == 'H' {
que.push_back((i, j));
seen[i][j] = 0;
}
}
while let Some((pi, pj)) = que.pop_front() {
for r in 0..4 {
let ni = pi.wrapping_add(DI[r]);
let nj = pj.wrapping_add(DJ[r]);
if ni < h && nj < w && s[ni][nj] == '.' && seen[ni][nj] == inf {
seen[ni][nj] = seen[pi][pj] + 1;
que.push_back((ni, nj));
}
}
}
println!("{}", seen.iter().flatten().filter(|&cnt| *cnt <= d).count());
}
pub static INF: u64 = 1e18 as u64;
pub static DI: &[usize] = &[0, !0, 0, 1];
pub static DJ: &[usize] = &[!0, 0, 1, 0];
pub static DC: &[char] = &['L', 'U', 'R', 'D'];
pub trait Debuggable {
fn debug_string(&self) -> String;
}
impl<T: std::fmt::Debug + std::fmt::Display> Debuggable for Vec<T> {
fn debug_string(&self) -> String {
use itertools::Itertools;
use std::iter::repeat;
if let Some(max_size) = self.iter()
.map(|x| format!("{:?}", x).len())
.max() {
let mut idx = String::from("idx |");
let mut val = String::from("val |");
for (i, xi) in self.iter().enumerate() {
idx.push_str(
&format!(" {:>w$} |", i, w=max_size)
);
val.push_str(
&format!(" {:>w$} |", xi, w=max_size)
);
}
format!("{}\n{}\n{}\n", idx, repeat('-').take(idx.len()).join(""), val)
} else {
format!("idx | \nval |\n")
}
}
}
impl<T: std::fmt::Debug + std::fmt::Display> Debuggable for std::collections::BTreeSet<T> {
fn debug_string(&self) -> String {
use itertools::Itertools;
format!("{{ {} }}", self.iter().join(", "))
}
}
impl<T, U> Debuggable for std::collections::BTreeMap<T, U>
where T: std::fmt::Debug + std::fmt::Display, U: std::fmt::Debug + std::fmt::Display
{
fn debug_string(&self) -> String {
use itertools::Itertools;
format!(
"{{\n{}\n }}", self.iter()
.map(|(k, v)| format!("{k} -> {v}, "))
.join("\n")
)
}
}
// lg! マクロの定義
#[macro_export]
macro_rules! lg {
($val:expr) => {
#[cfg(feature = "local")]
{
{
use Debuggable;
let val = &$val;
eprintln!(
"[{}:{}] {} = \n{}",
file!(),
line!(),
stringify!($val),
val.debug_string()
);
val
}
}
}
}
Submission Info
Submission Time |
|
Task |
C - Humidifier 3 |
User |
ardRiriy |
Language |
Rust (rustc 1.70.0) |
Score |
350 |
Code Size |
3124 Byte |
Status |
AC |
Exec Time |
33 ms |
Memory |
18748 KiB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
350 / 350 |
Status |
|
|
Set Name |
Test Cases |
Sample |
00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt |
All |
00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt, 01_test_33.txt, 01_test_34.txt, 01_test_35.txt, 01_test_36.txt |
Case Name |
Status |
Exec Time |
Memory |
00_sample_01.txt |
AC |
1 ms |
1932 KiB |
00_sample_02.txt |
AC |
1 ms |
2044 KiB |
00_sample_03.txt |
AC |
0 ms |
1972 KiB |
01_test_01.txt |
AC |
32 ms |
18748 KiB |
01_test_02.txt |
AC |
32 ms |
18536 KiB |
01_test_03.txt |
AC |
32 ms |
18736 KiB |
01_test_04.txt |
AC |
31 ms |
18680 KiB |
01_test_05.txt |
AC |
33 ms |
18592 KiB |
01_test_06.txt |
AC |
32 ms |
18696 KiB |
01_test_07.txt |
AC |
32 ms |
18732 KiB |
01_test_08.txt |
AC |
31 ms |
18728 KiB |
01_test_09.txt |
AC |
32 ms |
18520 KiB |
01_test_10.txt |
AC |
32 ms |
18696 KiB |
01_test_11.txt |
AC |
7 ms |
5692 KiB |
01_test_12.txt |
AC |
4 ms |
4088 KiB |
01_test_13.txt |
AC |
1 ms |
2044 KiB |
01_test_14.txt |
AC |
1 ms |
2344 KiB |
01_test_15.txt |
AC |
4 ms |
3812 KiB |
01_test_16.txt |
AC |
7 ms |
5192 KiB |
01_test_17.txt |
AC |
7 ms |
5040 KiB |
01_test_18.txt |
AC |
19 ms |
11304 KiB |
01_test_19.txt |
AC |
17 ms |
13188 KiB |
01_test_20.txt |
AC |
1 ms |
2216 KiB |
01_test_21.txt |
AC |
9 ms |
14596 KiB |
01_test_22.txt |
AC |
9 ms |
14528 KiB |
01_test_23.txt |
AC |
10 ms |
14648 KiB |
01_test_24.txt |
AC |
9 ms |
14600 KiB |
01_test_25.txt |
AC |
9 ms |
14556 KiB |
01_test_26.txt |
AC |
9 ms |
14552 KiB |
01_test_27.txt |
AC |
9 ms |
14548 KiB |
01_test_28.txt |
AC |
9 ms |
14568 KiB |
01_test_29.txt |
AC |
1 ms |
1964 KiB |
01_test_30.txt |
AC |
0 ms |
1916 KiB |
01_test_31.txt |
AC |
0 ms |
1968 KiB |
01_test_32.txt |
AC |
0 ms |
1864 KiB |
01_test_33.txt |
AC |
16 ms |
14564 KiB |
01_test_34.txt |
AC |
17 ms |
14544 KiB |
01_test_35.txt |
AC |
16 ms |
14564 KiB |
01_test_36.txt |
AC |
16 ms |
14584 KiB |