#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int MOD = 201712111; const int INF = INT_MAX / 2; int main() { int h, w; cin >> h >> w; vector > grid(h, vector(w, -1)); for(int y=0; y> c; if(c != '?') grid[y][x] = c - '0'; } } if(h < w){ swap(h, w); vector > grid2(h, vector(w)); for(int y=0; y > isUnknown(h, vector(w, false)); for(int y=0; y > minCost(h, vector(w, INF)); minCost[0][0] = grid[0][0]; for(int y=0; y 0) minCost[y][x] = min(minCost[y][x], minCost[y-1][x] + grid[y][x]); if(x > 0) minCost[y][x] = min(minCost[y][x], minCost[y][x-1] + grid[y][x]); } } vector dp(1< nextDp(1< bs(i); bitset<32> bs2 = (bs << 1) & bitset<32>((1 << w) - 1); if(isUnknown[y][x]){ nextDp[bs2.to_ulong()] += dp[i] * 8; nextDp[bs2.to_ulong()] %= MOD; } if((y > 0 && bs[w-1] && minCost[y-1][x] + grid[y][x] == minCost[y][x]) || (x > 0 && bs[0] && minCost[y][x-1] + grid[y][x] == minCost[y][x])){ bs2[0] = true; } nextDp[bs2.to_ulong()] += dp[i]; nextDp[bs2.to_ulong()] %= MOD; } dp.swap(nextDp); } } int ans = 0; for(int i=1; i<(1<