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
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <chrono>
#include <random>
#include <unordered_map>

using namespace std;

char s[10][10];
char t[10][10];

char tmp[10][10];

pair<int, int> dir[4] = { {-1,0}, {1,0}, {0,-1}, {0,1}};

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef uint64_t hash_t;

const hash_t HASH_P = (uint32_t) -13337;
uniform_int_distribution<hash_t> MULT_DIST(0.25 * HASH_P, 0.75 * HASH_P);



int main()
{
  
  //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  srand(chrono::steady_clock::now().time_since_epoch().count());
  
  
  //mt19937 rnd(1234);
  
  //printf("%d\n", rnd());
  
//  return 0;

  mt19937 rng(chrono::steady_clock().now().time_since_epoch().count());
  
  int n, m;
  scanf("%d %d", &n, &m);
  
  for (int i = 0; i < n; i++)
  {
    scanf("%s", s[i]);
    strcpy(tmp[i], s[i]);
  }

  for (int i = 0; i < n; i++)
  {
    scanf("%s", t[i]);
  }
  
  
  
  
  double prob = 0.0;
  
  for (int avg = 0; avg < 1; avg++)
  {
    int wins = 0;
  for (int z = 0; z < 100; z++)
  {

  
    
    for (int i = 0; i < n; i++) strcpy(s[i], tmp[i]);
  
  for (int loops = 0; loops < 10000; loops++)
  {
    pair<int, int> gdzie[8];
    int g = 0;
    for (int i = 0; i < n; i++)
    {
      for (int j = 0; j < m; j++)
      {
        if (s[i][j] == 'O')
        {
          gdzie[g] = {i, j};
          g++;
        }
      }
    }
    
    //int w = 1LL * rand() * rand() % g;
    
    
    //mt19937 rnd(g);
    
    //uniform_int_distribution<long long>(0, g - 1)(rng);
    
    //int w = rng() % g;
    
    
    pair<int, int> to[400];
    pair<int, int> from[400];
    int to_cnt = 0;
    
    
    for (int i = 0; i < g; i++)
    {
      for (int d = 0; d < 4; d++)
      {
        int posr = gdzie[i].first;
        int posc = gdzie[i].second;
        
        //printf("i %d j %d posr %d posc %d\n", i,j,posr, posc);
        
        if (posr + dir[d].first >= 0 && posr + dir[d].first < n && posc + dir[d].second >= 0 && posc + dir[d].second < m)
        {
          //printf("%d %d\n", posr + i, posc +j);
          if (s[posr + dir[d].first][posc + dir[d].second] == '.')
          {
            from[to_cnt].first = posr;
            from[to_cnt].second = posc;
            to[to_cnt].first = posr + dir[d].first;
            to[to_cnt].second = posc + dir[d].second;
            to_cnt++;
          }
        }
      }
    }
    
    if (to_cnt > 0)
    {
      //int to_nr = 1LL * rand() % to_cnt;
      //mt19937 rnd(to_cnt);
      
      //uniform_int_distribution<long long>(0, to_cnt - 1)(rng);
      
      //int to_nr = z % to_cnt;
      int to_nr = (z)% to_cnt;
      //int to_nr = rng() % to_cnt;
      
      int posr = from[to_nr].first;
      int posc = from[to_nr].second;

      int tor = to[to_nr].first ;
      int toc = to[to_nr].second;
      
      //printf("%d %d %d %d\n", posr, posc, tor, toc);
      
      s[posr][posc] = '.';
      s[tor][toc] = 'O';
    }
    

   

    for (int i = 0; i < n; i++)
    {
    //  printf("%s\n", s[i]);
    }
    //printf("\n");

    
    
  }
      bool ok = true;
    for (int i = 0; i < n; i++)
    {
      for (int j = 0; j < m; j++)
      {
        if (s[i][j] != t[i][j])
        {
          ok = false;
        }
      }
    }

  if (ok) wins++;
    }

//  printf("%d\n", wins);
  prob += (double)wins/10000 ;
  printf("%lf\n", (double)wins/100 * (double) wins/100);
  
  }
  
  return 0;
}