use proconio::input; use proconio::marker::Chars; fn main () { input! { h: usize, w: usize, a: [Chars;h], } //println!("{:?}", a); let mut q : Vec<(usize, usize, i32)> = Vec::new(); q.push((0,0,1)); let mut ans = 0; while !q.is_empty() { let v = q.pop().unwrap(); let x = v.0; let y = v.1; let jew = v.2; if x == w-1 && y == h-1 { ans += 1; continue; } if jew == -1 { continue; } //right if x+1 < w && a[x+1][y] != '#' { let j = if a[x+1][y] == 'o' {1} else {-1}; q.push((x+1, y, jew+j)); } if y+1 < h && a[x][y+1] != '#' { let j = if a[x][y+1] == 'o' {1} else {-1}; q.push((x, y+1, jew+j)); } //println!("q: {:?}", q); } println!("{}", ans); }