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][j] = s[h - i - 1][j]; } } let ans = if (0..h).all(|i| (0..w).all(|j| s[i][j] != t[i][j])) { 3.531740190461733 } else if (0..h).all(|i| (0..w).all(|j| s_rev[i][j] != t[i][j])) { 3.128936827211877 } else { -1.0 }; println!("{}", ans); }