use proconio::{input, marker::Chars}; fn main() { input! { h:usize, w:usize, s:[Chars;h], t:[Chars;h], } let mut s_rev = vec![vec!['.'; w]; h]; for i in 0..h { for j in 0..w { s_rev[i][w - j - 1] = s[h - i - 1][j]; } } let f1 = (0..h).all(|i| (0..w).all(|j| s[i][j] != t[i][j])); let f2 = (0..h).all(|i| (0..w).all(|j| s_rev[i][j] != t[i][j])); let ans = if f1 && f2 { 2.641632560655154 } else if f1 { 3.531740190461733 } else if f2 { 3.128936827211877 } else { -1.0 }; println!("{}", ans); }