import sys
header_line = sys.stdin.readline()
header_line = header_line.split(" ")
R = int(header_line[0])
C = int(header_line[1])
D = int(header_line[2])
K = int(header_line[3])
G = []
for i in range(R):
G.append(sys.stdin.readline())
P = []
for i in range(R + 1):
P_row = []
for j in range(C + 1):
P_row.append(0)
P.append(P_row)
for i in range(R):
for j in range(C):
if G[i][j] == 'S':
li = max(0, i - D)
hi = min(R - 1, i + D)
lj = max(0, j - D)
hj = min(C - 1, j + D)
P[li][lj] += 1
P[li][hj + 1] -= 1
P[hi + 1][lj] -= 1
P[hi + 1][hj + 1] += 1
for i in range(1, R):
for j in range(C):
P[i][j] += P[i - 1][j]
for i in range(R):
for j in range(1, C):
P[i][j] += P[i][j - 1]
ans = 0
for i in range(R):
for j in range(C):
if G[i][j] == 'M' and P[i][j] >= K:
ans += 1
print(ans)
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
3428 KB |
Output is correct |
2 |
Correct |
36 ms |
3676 KB |
Output is correct |
3 |
Correct |
33 ms |
3428 KB |
Output is correct |
4 |
Correct |
24 ms |
3428 KB |
Output is correct |
5 |
Correct |
23 ms |
3428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
3428 KB |
Output is correct |
2 |
Correct |
36 ms |
3676 KB |
Output is correct |
3 |
Correct |
33 ms |
3428 KB |
Output is correct |
4 |
Correct |
24 ms |
3428 KB |
Output is correct |
5 |
Correct |
23 ms |
3428 KB |
Output is correct |
6 |
Correct |
23 ms |
3340 KB |
Output is correct |
7 |
Correct |
25 ms |
3400 KB |
Output is correct |
8 |
Correct |
44 ms |
3676 KB |
Output is correct |
9 |
Correct |
26 ms |
3428 KB |
Output is correct |
10 |
Correct |
23 ms |
3428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
3380 KB |
Output is correct |
2 |
Correct |
31 ms |
3428 KB |
Output is correct |
3 |
Correct |
35 ms |
3428 KB |
Output is correct |
4 |
Correct |
26 ms |
3448 KB |
Output is correct |
5 |
Correct |
28 ms |
3428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
222 ms |
5360 KB |
Output is correct |
2 |
Correct |
232 ms |
8428 KB |
Output is correct |
3 |
Correct |
268 ms |
5600 KB |
Output is correct |
4 |
Correct |
239 ms |
11868 KB |
Output is correct |
5 |
Correct |
230 ms |
5368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
701 ms |
27688 KB |
Output is correct |
2 |
Correct |
514 ms |
17104 KB |
Output is correct |
3 |
Correct |
551 ms |
27912 KB |
Output is correct |
4 |
Correct |
1036 ms |
27740 KB |
Output is correct |
5 |
Correct |
699 ms |
27888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
3428 KB |
Output is correct |
2 |
Correct |
36 ms |
3676 KB |
Output is correct |
3 |
Correct |
33 ms |
3428 KB |
Output is correct |
4 |
Correct |
24 ms |
3428 KB |
Output is correct |
5 |
Correct |
23 ms |
3428 KB |
Output is correct |
6 |
Correct |
23 ms |
3340 KB |
Output is correct |
7 |
Correct |
25 ms |
3400 KB |
Output is correct |
8 |
Correct |
44 ms |
3676 KB |
Output is correct |
9 |
Correct |
26 ms |
3428 KB |
Output is correct |
10 |
Correct |
23 ms |
3428 KB |
Output is correct |
11 |
Correct |
25 ms |
3380 KB |
Output is correct |
12 |
Correct |
31 ms |
3428 KB |
Output is correct |
13 |
Correct |
35 ms |
3428 KB |
Output is correct |
14 |
Correct |
26 ms |
3448 KB |
Output is correct |
15 |
Correct |
28 ms |
3428 KB |
Output is correct |
16 |
Correct |
222 ms |
5360 KB |
Output is correct |
17 |
Correct |
232 ms |
8428 KB |
Output is correct |
18 |
Correct |
268 ms |
5600 KB |
Output is correct |
19 |
Correct |
239 ms |
11868 KB |
Output is correct |
20 |
Correct |
230 ms |
5368 KB |
Output is correct |
21 |
Correct |
701 ms |
27688 KB |
Output is correct |
22 |
Correct |
514 ms |
17104 KB |
Output is correct |
23 |
Correct |
551 ms |
27912 KB |
Output is correct |
24 |
Correct |
1036 ms |
27740 KB |
Output is correct |
25 |
Correct |
699 ms |
27888 KB |
Output is correct |
26 |
Correct |
825 ms |
27324 KB |
Output is correct |
27 |
Correct |
688 ms |
24028 KB |
Output is correct |
28 |
Correct |
989 ms |
23820 KB |
Output is correct |
29 |
Correct |
755 ms |
23968 KB |
Output is correct |
30 |
Correct |
744 ms |
26356 KB |
Output is correct |