1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef pair<int,long long> PIL;
const int mod = 1e9+7;

int n, m;
string arr[10];
string brr[10];

int calc(){
    int res = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m-1;j++){
            if(brr[i][j] != brr[i][j+1]) res++;
        }
    }
    for(int i=0;i<n-1;i++){
        for(int j=0;j<m;j++){
            if(brr[i][j] != brr[i+1][j]) res++;
        }
    }
    return res;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin>>n>>m;
    int sumA = 0;
    int cnt = 0;
    for(int i=0;i<n;i++) cin>>arr[i];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(arr[i][j] == 'O') sumA += i+j, cnt++;
        }
    }
    int sumB = 0;
    for(int i=0;i<n;i++) cin>>brr[i];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(brr[i][j] == 'O') sumB += i+j;
        }
    }

    if(sumA%2 != sumB%2) return cout<<0<<endl, 0;

    long long d = 2*n*m-n-m;
    for(int i=1;i<cnt;i++){
        d *= n*m-1-i;
        d /= i;
    }
    long double c = calc();
    //cout<<c<<" "<<d<<endl;
    cout.precision(17);
    cout<<fixed<<c/d<<endl;
}