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
57
58
59
60
61
62
63
64
65
66
67
#include <bits/stdc++.h>
using namespace std;

long long ch[100][100][2];

long long licP(int sp, int rem, int x0)
{
    if (rem == 0)
    {
        return x0 == 0;
    }
    if (rem > 0 && sp <= 0)
        return 0;
    if (ch[sp][rem][x0] != -1)
        return ch[sp][rem][x0];
    long long wn = 0;
    for (int i = 0; i < sp; i++)
    {
        wn += licP(i, rem - 1, x0 ^ (i % 2));
    }
    ch[sp][rem][x0] = wn;
    return wn;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<vector<bool>> t[2] = {vector<vector<bool>>(n, vector<bool>(m)), vector<vector<bool>>(n, vector<bool>(m))};
    bool X0 = 0, X1 = 0;
    int C = 0;
    for (int i = 0; i < 100; i++)
        for (int j = 0; j < 100; j++)
            ch[i][j][0] = ch[i][j][1] = -1;
    for (int z = 0; z < 2; z++)
    {
        for (int i = 0; i < n; i++)
        {
            string s;
            cin >> s;
            for (int j = 0; j < m; j++)
            {
                t[z][i][j] = (s[j] == 'O');
                if (s[j] == 'O')
                {
                    if (z == 0)
                    {
                        X1 ^= i % 2;
                        X1 ^= j % 2;
                    }
                    C++;
                    X0 ^= i % 2;
                    X0 ^= j % 2;
                }
            }
        }
    }
    C /= 2;
    if (X0)
    {
        cout << "0\n";
        return 0;
    }
    double long a = 1, b = licP(n * m, C, X1);
    cout << fixed << setprecision(15) << a / b << '\n';
}