1 #include <functional>
2 #include <algorithm>
3 #include <stdexcept>
4 #include <iostream>
5 #include <sstream>
6 #include <fstream>
7 #include <iomanip>
8 #include <cstdlib>
9 #include <cstring>
10 #include <utility>
11 #include <cctype>
12 #include <vector>
13 #include <string>
14 #include <bitset>
15 #include <queue>
16 #include <stack>
17 #include <ctime>
18 #include <list>
19 #include <map>
20 #include <set>
21 #include <cmath>
22
23 using namespace std;
24
25 #define pb push_back
26 #define INF 100000000000
27 #define L(s) (int)((s).size())
28 #define FOR(i,a,b) for (int _n(b), i(a); i<=_n; i++)
29 #define rep(i,n) FOR(i,1,(n))
30 #define rept(i,n) FOR(i,0,(n)-1)
31 #define C(a) memset((a), 0, sizeof(a))
32 #define ll long long
33 #define VI vector<int>
34 #define ppb pop_back
35 #define mp make_pair
36 #define MOD 1000000007
37 int toInt(string s){ istringstream sin(s); int t; sin>>t;return t;}
38
39 class GooseInZooDivTwo {
40 public:
41 struct Node {
42 int x;
43 int y;
44 Node(int a, int b) : x(a), y(b) { }
45 };
46
47 vector<Node> flood(vector<string> &field, vector<vector<bool>> &visit, int x, int y, int dist, int m, int n)
48 {
49 vector<Node> ret;
50 queue<Node> S;
51 visit[x][y] = true;
52 S.push(Node(x, y));
53 while (!S.empty())
54 {
55 Node cur = S.front();
56 ret.pb(S.front());
57 S.pop();
58 for (int i = max(0, cur.x-dist); i <= min(m-1, cur.x+dist); i++)
59 {
60 for (int j = max(0, cur.y-dist); j <= min(n-1, cur.y+dist); j++)
61 {
62 if (field[i][j] == 'v' && !visit[i][j] && (abs(i-cur.x)+abs(j-cur.y) <= dist))
63 {
64 S.push(Node(i, j));
65 visit[i][j] = true;
66 }
67 }
68 }
69 }
70 return ret;
71 }
72
73 int count(vector <string> field, int dist) {
74 int m = L(field);
75 if (!m) return 0;
76 int n = L(field[0]);
77 vector<vector<bool>> visit(m, vector<bool>(n, false));
78 vector<vector<Node>> ret;
79 rept(i, m)
80 {
81 rept(j, n)
82 {
83 if (field[i][j] == 'v' && !visit[i][j])
84 {
85 ret.pb(flood(field, visit, i, j, dist, m, n));
86 }
87 }
88 }
89 if (!L(ret)) return 0;
90 return (int(pow(2.0, L(ret)))-1)%MOD;
91 }
92
93 // BEGIN CUT HERE
94 public:
95 void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); }
96 private:
97 template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
98 void verify_case(int Case, const int &Expected, const int &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
99 void test_case_0() { string Arr0[] = {"vvv"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 0; int Arg2 = 7; verify_case(0, Arg2, count(Arg0, Arg1)); }
100 void test_case_1() { string Arr0[] = {"."}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 100; int Arg2 = 0; verify_case(1, Arg2, count(Arg0, Arg1)); }
101 void test_case_2() { string Arr0[] = {"vvv"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 1; int Arg2 = 1; verify_case(2, Arg2, count(Arg0, Arg1)); }
102 void test_case_3() { string Arr0[] = {"v.v..................v............................"
103 ,".v......v..................v.....................v"
104 ,"..v.....v....v.........v...............v......v..."
105 ,".........vvv...vv.v.........v.v..................v"
106 ,".....v..........v......v..v...v.......v..........."
107 ,"...................vv...............v.v..v.v..v..."
108 ,".v.vv.................v..............v............"
109 ,"..vv.......v...vv.v............vv.....v.....v....."
110 ,"....v..........v....v........v.......v.v.v........"
111 ,".v.......v.............v.v..........vv......v....."
112 ,"....v.v.......v........v.....v.................v.."
113 ,"....v..v..v.v..............v.v.v....v..........v.."
114 ,"..........v...v...................v..............v"
115 ,"..v........v..........................v....v..v..."
116 ,"....................v..v.........vv........v......"
117 ,"..v......v...............................v.v......"
118 ,"..v.v..............v........v...............vv.vv."
119 ,"...vv......v...............v.v..............v....."
120 ,"............................v..v.................v"
121 ,".v.............v.......v.........................."
122 ,"......v...v........................v.............."
123 ,".........v.....v..............vv.................."
124 ,"................v..v..v.........v....v.......v...."
125 ,"........v.....v.............v......v.v............"
126 ,"...........v....................v.v....v.v.v...v.."
127 ,"...........v......................v...v..........."
128 ,"..........vv...........v.v.....................v.."
129 ,".....................v......v............v...v...."
130 ,".....vv..........................vv.v.....v.v....."
131 ,".vv.......v...............v.......v..v.....v......"
132 ,"............v................v..........v....v...."
133 ,"................vv...v............................"
134 ,"................v...........v........v...v....v..."
135 ,"..v...v...v.............v...v........v....v..v...."
136 ,"......v..v.......v........v..v....vv.............."
137 ,"...........v..........v........v.v................"
138 ,"v.v......v................v....................v.."
139 ,".v........v................................v......"
140 ,"............................v...v.......v........."
141 ,"........................vv.v..............v...vv.."
142 ,".......................vv........v.............v.."
143 ,"...v.............v.........................v......"
144 ,"....v......vv...........................v........."
145 ,"....vv....v................v...vv..............v.."
146 ,".................................................."
147 ,"vv........v...v..v.....v..v..................v...."
148 ,".........v..............v.vv.v.............v......"
149 ,".......v.....v......v...............v............."
150 ,"..v..................v................v....v......"
151 ,".....v.....v.....................v.v......v......."}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 3; int Arg2 = 797922654; verify_case(3, Arg2, count(Arg0, Arg1)); }
152
153 // END CUT HERE
154
155 };
156
157 // BEGIN CUT HERE
158 int main() {
159 GooseInZooDivTwo ___test;
160 ___test.run_test(-1);
161 }
162 // END CUT HERE