結果
問題 | No.179 塗り分け |
ユーザー | gemmaro |
提出日時 | 2020-11-05 11:33:49 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,561 bytes |
コンパイル時間 | 14,118 ms |
コンパイル使用メモリ | 378,968 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-22 10:54:59 |
合計ジャッジ時間 | 16,093 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | WA | - |
testcase_08 | AC | 18 ms
5,376 KB |
testcase_09 | AC | 18 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | AC | 11 ms
5,376 KB |
testcase_13 | AC | 1 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 1 ms
5,376 KB |
testcase_16 | AC | 1 ms
5,376 KB |
testcase_17 | AC | 1 ms
5,376 KB |
testcase_18 | AC | 1 ms
5,376 KB |
testcase_19 | AC | 1 ms
5,376 KB |
testcase_20 | AC | 11 ms
5,376 KB |
testcase_21 | AC | 17 ms
5,376 KB |
testcase_22 | AC | 19 ms
5,376 KB |
testcase_23 | AC | 1 ms
5,376 KB |
testcase_24 | AC | 15 ms
5,376 KB |
testcase_25 | AC | 1 ms
5,376 KB |
testcase_26 | AC | 3 ms
5,376 KB |
testcase_27 | AC | 18 ms
5,376 KB |
testcase_28 | AC | 1 ms
5,376 KB |
testcase_29 | AC | 16 ms
5,376 KB |
testcase_30 | AC | 8 ms
5,376 KB |
testcase_31 | AC | 14 ms
5,376 KB |
testcase_32 | AC | 5 ms
5,376 KB |
testcase_33 | AC | 16 ms
5,376 KB |
testcase_34 | AC | 3 ms
5,376 KB |
testcase_35 | AC | 15 ms
5,376 KB |
testcase_36 | AC | 1 ms
5,376 KB |
testcase_37 | AC | 1 ms
5,376 KB |
testcase_38 | AC | 1 ms
5,376 KB |
testcase_39 | AC | 1 ms
5,376 KB |
testcase_40 | AC | 1 ms
5,376 KB |
testcase_41 | AC | 1 ms
5,376 KB |
testcase_42 | AC | 1 ms
5,376 KB |
testcase_43 | AC | 1 ms
5,376 KB |
testcase_44 | AC | 2 ms
5,376 KB |
testcase_45 | AC | 1 ms
5,376 KB |
ソースコード
use std::{convert::TryInto, io::stdin}; fn main() { let (h, w) = { let mut buf = String::new(); stdin().read_line(&mut buf).unwrap(); let mut h_and_w = buf.split_whitespace().map(|s| s.parse::<u8>().unwrap()); (h_and_w.next().unwrap(), h_and_w.next().unwrap()) }; let ss: Vec<Vec<Square>> = { (1..=h) .map(|_i| { let mut buf = String::new(); stdin().read_line(&mut buf).unwrap(); buf.trim_end().chars().map(|c| c.into()).collect() }) .collect() }; println!("{}", solve(h, w, ss)); } fn solve(h: u8, w: u8, ss: Vec<Vec<Square>>) -> &'static str { if any_overlap(h, w, ss) { "YES" } else { "NO" } } fn any_overlap(h: u8, w: u8, ss: Vec<Vec<Square>>) -> bool { for vec_row in 0..(h as i8) { for vec_col in (-(w as i8) + 1)..(w as i8) { if is_overlap(vec_row, vec_col, h, w, ss.clone()) { return true; } } } false } fn is_overlap(vec_row: i8, vec_col: i8, h: u8, w: u8, ss: Vec<Vec<Square>>) -> bool { if vec_row == 0 && vec_col == 0 { return false; } let mut ss = ss; for src_row in 0..h { for src_col in 0..w { let src_row = src_row as usize; let src_col = src_col as usize; if let Square::Black = ss[src_row][src_col] { let dst_row = (src_row as i8) + vec_row; let dst_col = (src_col as i8) + vec_col; if !in_rect(dst_row, dst_col, h, w) { return false; } let dst_row = dst_row as usize; let dst_col = dst_col as usize; if let Square::Black = ss[dst_row][dst_col] { ss[src_row][src_col] = Square::White; ss[dst_row][dst_col] = Square::White; } } } } all_black(ss) } fn in_rect(row: i8, col: i8, h: u8, w: u8) -> bool { row >= 0 && row <= (h - 1).try_into().unwrap() && col >= 0 && col <= (w - 1).try_into().unwrap() } fn all_black(ss: Vec<Vec<Square>>) -> bool { ss.iter() .all(|row| row.iter().all(|&col| col == Square::White)) } #[derive(PartialEq, Copy, Clone, Debug)] enum Square { White, Black, } impl From<char> for Square { fn from(c: char) -> Self { match c { '#' => Self::Black, '.' => Self::White, _ => unreachable!(), } } }