結果

問題 No.179 塗り分け
ユーザー iwotiwot
提出日時 2020-06-22 10:03:41
言語 Rust
(1.77.0)
結果
AC  
実行時間 135 ms / 3,000 ms
コード長 2,029 bytes
コンパイル時間 1,073 ms
コンパイル使用メモリ 154,232 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-30 21:28:03
合計ジャッジ時間 4,036 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 12 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 63 ms
4,380 KB
testcase_09 AC 63 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 68 ms
4,384 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 68 ms
4,376 KB
testcase_21 AC 73 ms
4,376 KB
testcase_22 AC 75 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 69 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 19 ms
4,380 KB
testcase_27 AC 105 ms
4,380 KB
testcase_28 AC 10 ms
4,376 KB
testcase_29 AC 122 ms
4,376 KB
testcase_30 AC 66 ms
4,376 KB
testcase_31 AC 135 ms
4,376 KB
testcase_32 AC 45 ms
4,380 KB
testcase_33 AC 118 ms
4,380 KB
testcase_34 AC 36 ms
4,380 KB
testcase_35 AC 127 ms
4,380 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 4 ms
4,376 KB
testcase_44 AC 18 ms
4,376 KB
testcase_45 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable `H` should have a snake case name
  --> 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
  --> Main.rs:28:18
   |
28 |   read!(H:usize, W:usize);
   |                  ^ help: convert the identifier to snake case (notice the capitalization): `w`

warning: 2 warnings emitted

ソースコード

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