use std::collections::VecDeque; use itertools::Itertools; use proconio::{marker::{Bytes, Usize1}, *}; const DIFF_4: [(usize, usize); 4] = [(0, 1), (0, !0), (1, 0), (!0, 0)]; fn grid_move_iter<'a>(i: usize, j: usize, h: usize, w: usize, d: &'a[(usize, usize)]) -> impl Iterator + 'a { d.iter().filter_map(move |&(di, dj)| { let ni = i.wrapping_add(di); let nj = j.wrapping_add(dj); if ni < h && nj < w { Some((ni, nj)) } else { None } }) } fn main() { input! { h: usize, w: usize, t: usize, ss: (Usize1, Usize1), g: (Usize1, Usize1), ts: [Bytes; h], } let mut s = ts.iter().map(|b| b.iter().map(|&b| (b - b'0') as usize).collect_vec()).collect_vec(); let init = s.clone(); let mut ok = vec![vec![false; w]; h]; ok[ss.0][ss.1] = true; for _ in 0..t { for i in 0..h { for j in 0..w { if s[i][j] == 0 { s[i][j] = init[i][j]; } else { s[i][j] -= 1; } } } let mut nok = ok.clone(); for i in 0..h { for j in 0..w { if !ok[i][j] { continue; } for (ni, nj) in grid_move_iter(i, j, h, w, &DIFF_4) { if s[ni][nj] == 0 { continue; } nok[ni][nj] = ok[i][j]; } } } ok = nok; if ok[g.0][g.1] { println!("Yes"); return; } } println!("No"); }