use proconio::input; use proconio::fastout; use proconio::marker::Usize1; const DX: &[usize] = &[!0, 1, 0, 0]; const DY: &[usize] = &[ 0, 0,!0, 1]; #[allow(non_snake_case)] fn dfs(x: usize, y: usize, Gi: usize, Gj: usize, H: usize, W: usize, flg: &mut Vec>) -> usize { if Gi == x && Gj == y { return 1; } let mut ret = 0; for d in 0..4 { let nx = x.wrapping_add(DX[d]); let ny = y.wrapping_add(DY[d]); if nx >= H || ny >= W { continue; } if flg[nx][ny] { continue; } let mut cnt = 0; for d in 0..4 { let mx = nx.wrapping_add(DX[d]); let my = ny.wrapping_add(DY[d]); if mx >= H || my >= W { continue; } if flg[mx][my] { cnt += 1; } } if cnt == 1 { flg[nx][ny] = true; ret += dfs(nx, ny, Gi, Gj, H, W, flg); flg[nx][ny] = false; } } return ret; } #[fastout] #[allow(non_snake_case)] fn main() { input! { (H, W): (usize, usize), (Si, Sj): (Usize1, Usize1), (Gi, Gj): (Usize1, Usize1), } assert!(1 <= H && H <= 6); assert!(1 <= W && W <= 6); assert!(Si < H); assert!(Gi < H); assert!(Sj < W); assert!(Gj < W); assert!(Si != Gi || Sj != Gj); let mut flg = vec![vec![false; W]; H]; flg[Si][Sj] = true; println!("{}", dfs(Si, Sj, Gi, Gj, H, W, &mut flg)); }