# Yukicoder No.226 0-1パズル

,

http://yukicoder.me/problems/600

## solution

0000000000000000
????????????????
????????????????
????????????????
????????????????
????????????????

|
v

0000000000000000
1111111111111111
0000000000000000
1111111111111111
0000000000000000
1111111111111111


0000000111100100
????????????????
????????????????
????????????????
????????????????
????????????????

|
v

0000000111100100
1111111000011011
0000000111100100
1111111000011011
0000000111100100
1111111000011011


## implementation

#include <iostream>
#include <vector>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
using ll = long long;
using namespace std;
const int mod = 1e9+7;
int count1(vector<string> const & f) {
int h = f.size();
int w = f.front().size();
ll acc = 1;
repeat (x,w) {
int sats = 0;
repeat (p,2) {
bool sat = true;
repeat (y,h) {
int clr = (x % 2) ^ p ^ (y % 2);
if (f[y][x] != '?' and f[y][x] - '0' != clr) {
sat = false;
break;
}
}
sats += sat;
}
acc = acc * sats % mod;
if (not acc) break;
}
return acc;
}
int count2(vector<string> const & f) {
int h = f.size();
int w = f.front().size();
int acc = 0;
repeat (p,2) {
bool sat = true;
repeat (y,h) {
repeat (x,w) {
int clr = p ^ (x % 2) ^ (y % 2);
if (f[y][x] != '?' and f[y][x] - '0' != clr) {
sat = false;
break;
}
}
}
acc += sat;
}
return acc;
}
vector<string> transpose(vector<string> const & f) {
int h = f.size();
int w = f.front().size();
vector<string> g(w, string(h, '\0'));
repeat (x,w) repeat (y,h) g[x][y] = f[y][x];
return g;
}
int main() {
int h, w; cin >> h >> w;
vector<string> f(h); repeat (y,h) cin >> f[y];
ll ans = 0;
ans += count1(f);
ans += count1(transpose(f));
ans -= count2(f);
ans = (ans + mod) % mod;
cout << ans << endl;
return 0;
}