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
68
69
70
71
72
73
74
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
#define ll long long
using namespace std;
long double lb_p;
ll n,m,zero,t[2],sum[5],r,d[10][10];
int main()
{
    cout.precision(15);
    cin>>n>>m;
    for(ll i=1; i<=n; i++){
        r=i%2;
        for(ll j=1; j<=m; j++){
            char c; cin>>c;
            r++; r%=2;
            if(c=='O'){
                t[r]=1;
                lb_p++;
            }
                
        }
    }
    r=0;
        for(ll i=1; i<=n; i++){
            r=i%2;
            for(ll j=1; j<=m; j++){
                r++; r%=2;
                ll k=0;
                if(t[r]==1){
                    if(i>1)
                        k++;
                    if(i<n)
                        k++;
                    if(j>1)
                        k++;
                    if(j<m)
                        k++;
                    sum[k]++;
                }
                d[i][j]=k;
            }
        }
    /*for(ll i=1; i<=4; i++)
        cout<<sum[i]<<" ";
    cout<<"\n";
    for(ll i=1; i<=n; i++){
        for(ll j=1; j<=m; j++){
            cout<<d[i][j]<<" ";
        }
        cout<<"\n";
    }*/
    long double a=0;
    for(ll i=1; i<=4; i++)
        a+=i*sum[i];
    long double x=lb_p/a;
    //cout<<x;
    long double res=1;
    for(ll i=1; i<=n; i++){
        for(ll j=1; j<=m; j++){
            char c; cin>>c;
            if(c=='O')
                res*=d[i][j]*x;
        }
    }
    cout<<res;
    return 0;
}