Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_DEPRECATE
- #include <algorithm>
- #include <string>
- #include <set>
- #include <map>
- #include <vector>
- #include <queue>
- #include <iostream>
- #include <iterator>
- #include <cmath>
- #include <cstdio>
- #include <cstdlib>
- #include <sstream>
- #include <fstream>
- #include <ctime>
- #include <cstring>
- #pragma comment(linker, "/STACK:66777216")
- using namespace std;
- #define pb push_back
- #define ppb pop_back
- #define pi 3.1415926535897932384626433832795028841971
- #define mp make_pair
- //#define x first
- //#define y second
- #define pii pair<int,int>
- #define pdd pair<double,double>
- #define INF 1000000000
- #define FOR(i,a,b) for (int _n(b), i(a); i <= _n; i++)
- #define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;i--)
- #define all(c) (c).begin(), (c).end()
- #define SORT(c) sort(all(c))
- #define rep(i,n) FOR(i,1,(n))
- #define rept(i,n) FOR(i,0,(n)-1)
- #define L(s) (int)((s).size())
- #define C(a) memset((a),0,sizeof(a))
- #define VI vector <int>
- #define ll long long
- #define rp rept
- #define inf INF
- #define problem ""
- int n, m;
- char a[13][13];
- ll f[2][2000000];
- int pws[13];
- int vals[13];
- inline void add(int num, int mask, ll val) {
- f[num][mask] += val;
- if (f[num][mask] >= (ll)inf*inf) {
- f[num][mask] -= (ll)inf *inf;
- }
- }
- int main()
- {
- pws[0] = 1;
- for(int i = 1; i < 13; ++i) pws[i] = pws[i - 1] * 3;
- freopen(problem "life.in","r",stdin);
- freopen(problem "life.out","w",stdout);
- cin >> m >> n;
- for(int i = 0; i < n; ++i)
- for(int j = 0; j < m; ++j)
- cin >> a[i][j];
- int lim = pws[m - 1] * 3;
- int cur = 0, nxt = 1;
- f[0][0] = 1;
- for(int i = 0; i < n; ++i)
- for(int j = 0; j < m; ++j) {
- for(int mask = 0; mask < lim; ++mask) {
- f[nxt][mask] = 0;
- }
- for(int mask = 0; mask < lim; ++mask) {
- if (!f[cur][mask]) continue;
- int x = mask;
- for(int t = 0; t < m; ++t) {
- vals[t] = x % 3;
- x /= 3;
- }
- bool can_put = 1;
- int put = mask;
- if (i > 0) {
- if (vals[0] == 1) can_put = false;
- else if (vals[0] == 0) put++;
- }
- if (j > 0) {
- if (vals[m - 1] == 1) can_put = false;
- else if (vals[m -1] == 0) put += pws[m - 1];
- }
- put = put / 3 + 2 * pws[m - 1];
- if (can_put) {
- add(nxt, put, f[cur][mask]);
- }
- if (a[i][j] == 'B') {
- continue;
- }
- int black = 0;
- if (i > 0 && vals[0] == 2) {
- ++black;
- }
- if (j > 0 && vals[m - 1] == 2) {
- ++black;
- }
- if (black == 2) {
- continue;
- }
- add(nxt, mask / 3 + pws[m - 1] * black, f[cur][mask]);
- }
- swap(cur, nxt);
- }
- ll ans = 0;
- for(int mask = 0; mask < lim; ++mask) {
- ans += f[cur][mask];
- if (ans >= (ll)inf *inf) {
- ans -= (ll)inf*inf;
- }
- }
- cout << ans << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement