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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(),(u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

const int MR = 3010;

char t[MR][MR];

int n;

int dr[4] = { 0,0,-1,1 };
int dc[4] = { -1,1,0,0 };

bool ok(int r, int c, int k)
{
	return r + dr[k] >= 0 && r + dr[k] < n && c + dc[k] >= 0 && c + dc[k] < n;
}

int cnt, done[MR][MR], allowedToVisit;

void dfs(int r, int c)
{
	done[r][c] = cnt;
	REP(l, 4)
		if (ok(r, c, l) && done[r + dr[l]][c + dc[l]] == allowedToVisit)
			dfs(r + dr[l], c + dc[l]);
}

set<vector<PII>> S;

void go(vector<PII> &check, int k)
{
	sort(check.begin(), check.end());

	check.resize(unique(check.begin(), check.end()) - check.begin());

	if (check.size() < k)
		return;

	vector<PII> umocowane, wolne;

	for (const auto &p : check)
	{
		// zobacz czy ma min 1 sasiada
		bool neighbour = 0;
		REP(l, 4)
			if (ok(p.first, p.second, l) && t[p.first + dr[l]][p.second + dc[l]] == '#')
			{
				neighbour = 1;
				umocowane.push_back(p);
				break;
			}
		if (!neighbour)
			wolne.push_back(p);
	}

	// wszystkie wolne musisz odwiedzic dfs-em - spr tylko umocowane jako poczatki
	cnt++;
	allowedToVisit = cnt;
	for (const auto &p : wolne)
		done[p.first][p.second] = allowedToVisit;
	for (const auto &p : umocowane)
		done[p.first][p.second] = allowedToVisit;

	cnt++;
	for (const auto &p : umocowane)
		if (done[p.first][p.second] == allowedToVisit)
			dfs(p.first, p.second);

	bool ok = 1;
	for (const auto &p : wolne)
		if (done[p.first][p.second] != cnt)
		{
			ok = 0;
			break;
		}

	if (ok)
		S.insert(check);
}

int main()
{
	int k;
	scanf("%d%d", &n, &k);

	REP(i, n)
		scanf("%s", t[i]);

	if (k == 1)
	{
		REP(i1, n)REP(j1, n)
			if (t[i1][j1] == '.')
			{
				vector<PII> check;
				check.push_back(MP(i1, j1));

				go(check, k);
			}
	}
	else if (k == 2)
	{
		REP(i1, n)REP(j1, n)
			if (t[i1][j1] == '.')
			{
				REP(i2, n)REP(j2, n)
					if (t[i2][j2] == '.')
					{
						vector<PII> check;
						check.push_back(MP(i1, j1));
						check.push_back(MP(i2, j2));

						go(check, k);
					}
			}
	}
	else if (k == 3)
	{
		REP(i1, n)REP(j1, n)
			if (t[i1][j1] == '.')
			{
				REP(i2, n)REP(j2, n)
					if (t[i2][j2] == '.')
					{
						REP(i3, n)REP(j3, n)
							if (t[i3][j3] == '.')
							{
								vector<PII> check;
								check.push_back(MP(i1, j1));
								check.push_back(MP(i2, j2));
								check.push_back(MP(i3, j3));

								go(check, k);
							}
					}
			}
	}
	else
	{
		REP(i1, n)REP(j1, n)
			if (t[i1][j1] == '.')
			{
				REP(i2, n)REP(j2, n)
					if (t[i2][j2] == '.')
					{
						REP(i3, n)REP(j3, n)
							if (t[i3][j3] == '.')
							{
								REP(i4, n)REP(j4, n)
									if (t[i4][j4] == '.')
									{
										vector<PII> check;
										check.push_back(MP(i1, j1));
										check.push_back(MP(i2, j2));
										check.push_back(MP(i3, j3));
										check.push_back(MP(i4, j4));

										go(check, k);
									}
							}
					}
			}
	}

	printf("%d\n", S.size());

	return 0;
}