結果

問題 No.179 塗り分け
ユーザー iwot
提出日時 2020-06-22 10:03:41
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 134 ms / 3,000 ms
コード長 2,029 bytes
コンパイル時間 13,751 ms
コンパイル使用メモリ 387,992 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-23 15:15:10
合計ジャッジ時間 16,848 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable `H` should have a snake case name
  --> src/main.rs:28:9
   |
28 |   read!(H:usize, W:usize);
   |         ^ help: convert the identifier to snake case: `h`
   |
   = note: `#[warn(non_snake_case)]` on by default

warning: variable `W` should have a snake case name
  --> src/main.rs:28:18
   |
28 |   read!(H:usize, W:usize);
   |                  ^ help: convert the identifier to snake case (notice the capitalization): `w`

ソースコード

diff #

fn read<T: std::str::FromStr>() -> T {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().parse().ok().unwrap()
}

macro_rules! read {
  ($x:ident, $v:expr, $idx:expr, $type:ty) => {
    let $x:$type = $v[$idx].clone().parse().unwrap();
  };

  ( $($x:ident:$t:ty),* ) => {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let input:Vec<String> = s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect();
    let mut idx:i64 = -1;
    $(
      idx += 1;
      read!($x, input, idx as usize, $t);
    )*
  };
}

fn main() {
  read!(H:usize, W:usize);
  let s:Vec<Vec<usize>> = (0..H).map(|_| {
    let line:String = read();
    line.chars().map(|c| if c == '#' {1} else {0}).collect()
  }).collect();

  let is_all_zero = |list: &Vec<Vec<usize>>| {
    for i in 0..list.len() {
      for j in 0..list[i].len() {
        if list[i][j] == 1 {
          return false;
        }
      }
    }
    true
  };

  if is_all_zero(&s) {
    println!("NO");
  } else {
    let mut dh_range: Vec<i64> = vec![];
    let mut dw_range: Vec<i64> = vec![];
    for i in 0..H {
      dh_range.push(-1*(i as i64));
      dh_range.push(i as i64);
    }
    for i in 0..W {
      dw_range.push(-1*(i as i64));
      dw_range.push(i as i64);
    }

    let mut result = "NO";
    'outer: for dh in &dh_range {
      for dw in &dw_range {
        if *dw == 0 && *dh == 0 {
          continue;
        }
        let mut check = s.clone();
        for h in 0..H {
          for w in 0..W {
            let nh = h as i64 + dh;
            let nw = w as i64 + dw;
            if nh >= 0 && nh < H as i64 && nw >= 0 && nw < W as i64 && check[h][w] == 1 && check[nh as usize][nw as usize] == 1 {
              check[h][w] = 0;
              check[nh as usize][nw as usize] = 0;
            }
          }
        }
        if is_all_zero(&check) {
          result = "YES";
          break 'outer;
        }
      }
    }
    println!("{}", result);
  }
}
0