package main import . "fmt" import . "strings" func main() { var h,w int Scan(&h,&w) ss:=make([]string,h) for i:=range ss { var s string Scan(&s) s=ReplaceAll(s,".","a") s=ReplaceAll(s,"#",".") ss[i]=ReplaceAll(s,"a","#") } var x,y int for i,s:=range ss { var t string Scan(&t) if s!=t { x++ } if ss[h-1-i]!=t { y++ } } if x>0&&y>0 { Println(-1) } else if x==0&&y>0 { Println("3.5317401904617327") } else { var e,f,z float64 e,f=2,1 for i:=0;i<1000;i++ { e/=2 if i%2==0 &&x>0{ continue } z+=float64(i+1)*f*(1-e) f*=e } Printf("%.12f\n",z) } }