Submission #1686498


Source Code Expand

fn main() {
  let (h, w): (usize, usize) = read_tuple();
  let pic: Vec<Vec<char>> = read_mat(h);

  let is_adj_all = |i,j| {
    let h = h as isize;
    let w = w as isize;
    let i = i as isize;
    let j = j as isize;
    let neighbor = [(i-1,j-1),(i-1,j),(i-1,j+1),(i,j-1),(i,j+1),(i+1,j-1),(i+1,j),(i+1,j+1)];
    neighbor.iter().filter(|&&(x,y)| 0<=x && x<h && 0<=y && y<w).all(|&(x,y)| pic[x as usize][y as usize]=='#')
  };

  let mut buf1 = pic.clone();
  for i in 0 .. h {
    for j in 0 .. w {
      if buf1[i][j] == '#' && is_adj_all(i,j) {continue}
      buf1[i][j] = '.'
    }
  }

  let is_adj_any = |i,j| {
    let h = h as isize;
    let w = w as isize;
    let i = i as isize;
    let j = j as isize;
    let neighbor = [(i-1,j-1),(i-1,j),(i-1,j+1),(i,j-1),(i,j+1),(i+1,j-1),(i+1,j),(i+1,j+1)];
    neighbor.iter().filter(|&&(x,y)| 0<=x && x<h && 0<=y && y<w).any(|&(x,y)| buf1[x as usize][y as usize]=='#')
  };

  let mut buf2 = buf1.clone();
  for i in 0 .. h {
    for j in 0 .. w {
      if buf1[i][j] == '#' || is_adj_any(i,j) {
        buf2[i][j] = '#'
      }
    }
  }

  if pic == buf2 {
    println!("possible");
    print_mat(&buf1, "");
  } else {
    println!("impossible");
  }
}

fn read_tuple<T1: std::str::FromStr, T2: std::str::FromStr>() -> (T1, T2) {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  let mut it = buf.trim().split_whitespace();
  let x = it.next().unwrap().parse::<T1>().ok().unwrap();
  let y = it.next().unwrap().parse::<T2>().ok().unwrap();
  (x, y)
}

fn read_vec() -> Vec<char> {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  buf.trim().chars().collect()
}

fn read_mat(h: usize) -> Vec<Vec<char>> {
  let mut mat: Vec<Vec<char>> = vec![];
  for _ in 0 .. h {
    mat.push(read_vec());
  }
  mat
}

fn print_vec<T: std::string::ToString>(vec: &Vec<T>, sep: &str) {
  let out = vec.iter().map(|e| e.to_string()).collect::<Vec<_>>().as_slice().join(sep);
  println!("{}", out);
}

fn print_mat<T: std::string::ToString>(mat: &Vec<Vec<T>>, sep: &str) {
  for v in mat {
    print_vec(v, sep);
  }
}

Submission Info

Submission Time
Task D - 画像処理高橋君
User aimy
Language Rust (1.15.1)
Score 100
Code Size 2196 Byte
Status AC
Exec Time 3 ms
Memory 4352 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 3
AC × 25
Set Name Test Cases
Sample example_0.txt, example_1.txt, example_2.txt
All example_0.txt, example_1.txt, example_2.txt, handmade_0.txt, handmade_1.txt, possible_0.txt, possible_1.txt, possible_2.txt, possible_3.txt, possible_4.txt, possible_5.txt, possible_6.txt, possible_7.txt, possible_8.txt, possible_9.txt, random_0.txt, random_1.txt, random_2.txt, random_3.txt, random_4.txt, random_5.txt, random_6.txt, random_7.txt, random_8.txt, random_9.txt
Case Name Status Exec Time Memory
example_0.txt AC 2 ms 4352 KB
example_1.txt AC 2 ms 4352 KB
example_2.txt AC 2 ms 4352 KB
handmade_0.txt AC 2 ms 4352 KB
handmade_1.txt AC 2 ms 4352 KB
possible_0.txt AC 2 ms 4352 KB
possible_1.txt AC 3 ms 4352 KB
possible_2.txt AC 3 ms 4352 KB
possible_3.txt AC 3 ms 4352 KB
possible_4.txt AC 2 ms 4352 KB
possible_5.txt AC 2 ms 4352 KB
possible_6.txt AC 2 ms 4352 KB
possible_7.txt AC 3 ms 4352 KB
possible_8.txt AC 3 ms 4352 KB
possible_9.txt AC 2 ms 4352 KB
random_0.txt AC 2 ms 4352 KB
random_1.txt AC 2 ms 4352 KB
random_2.txt AC 2 ms 4352 KB
random_3.txt AC 2 ms 4352 KB
random_4.txt AC 2 ms 4352 KB
random_5.txt AC 2 ms 4352 KB
random_6.txt AC 2 ms 4352 KB
random_7.txt AC 2 ms 4352 KB
random_8.txt AC 2 ms 4352 KB
random_9.txt AC 2 ms 4352 KB