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
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

const int maxn = 3005;
const ll md = 1000000007;

int n, k, t[maxn][maxn];
char s[maxn][maxn];

int main () {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++)
		scanf("%s", s[i] + 1);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (s[i][j] == '.')
				t[i][j] = 1;
			else
				t[i][j] = 2;
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (t[i][j] == 1) {
				for (int x = -1; x <= 1; x++) {
					for (int y = -1; y <= 1; y++) {
						if ((x == 0 && y != 0) || (y == 0 && x != 0)) {
							if (t[i + x][j + y] == 2) {
								t[i][j] = 3;
							}
						}
					}
				}
			}
		}
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (t[i][j] == 1) {
				for (int x = -1; x <= 1; x++) {
					for (int y = -1; y <= 1; y++) {
						if ((x == 0 && y != 0) || (y == 0 && x != 0)) {
							if (t[i + x][j + y] == 3) {
								t[i][j] = 4;
							}
						}
					}
				}
			}
		}
	}

	/*for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			printf("%d ", t[i][j]);
		}
		printf("\n");
	}*/

	ll res1 = 0LL;
	
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (t[i][j] == 3) {
				res1++;
			}
		}
	}

	ll res2 = 0LL;

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (t[i][j] == 4) {
				for (int x = -1; x <= 1; x++) {
					for (int y = -1; y <= 1; y++) {
						if ((x == 0 && y != 0) || (y == 0 && x != 0)) {
							if (t[i + x][j + y] == 3) {
								res2++;
							}
						}
					}
				}
			}
		}
	}

	if (k == 1)
		printf("%lld\n", res1 % md);
	else if (k == 2)
		printf("%lld\n", (((res1 * (res1 - 1))%md)/2LL+res2)%md);
	else {
		printf("wa\n");
	}
	return 0;
}