#include <stdio.h>
#define NM 500000
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
int main() {
static char cc[NM + 1];
static int kk[NM];
int n, m, d, k, i, il, ir, j, jl, jr, cnt;
scanf("%d%d%d%d", &n, &m, &d, &k);
for (i = 0; i < n; i++)
scanf("%s", cc + i * m);
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
if (cc[i * m + j] == 'S') {
il = max(i - d, 0), ir = min(i + d, n - 1), jl = max(j - d, 0), jr = min(j + d, m - 1);
kk[il * m + jl]++;
if (jr + 1 < m)
kk[il * m + (jr + 1)]--;
if (ir + 1 < n) {
kk[(ir + 1) * m + jl]--;
if (jr + 1 < m)
kk[(ir + 1) * m + (jr + 1)]++;
}
}
for (i = 0; i < n; i++)
for (j = 1; j < m; j++)
kk[i * m + j] += kk[i * m + (j - 1)];
for (i = 1; i < n; i++)
for (j = 0; j < m; j++)
kk[i * m + j] += kk[(i - 1) * m + j];
cnt = 0;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
if (cc[i * m + j] == 'M' && kk[i * m + j] >= k)
cnt++;
printf("%d\n", cnt);
return 0;
}
Compilation message
mushrooms.c: In function 'main':
mushrooms.c:13:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d%d%d%d", &n, &m, &d, &k);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mushrooms.c:15:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | scanf("%s", cc + i * m);
| ^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
292 KB |
Output is correct |
7 |
Correct |
0 ms |
296 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Correct |
0 ms |
296 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1460 KB |
Output is correct |
2 |
Correct |
2 ms |
1492 KB |
Output is correct |
3 |
Correct |
3 ms |
1748 KB |
Output is correct |
4 |
Correct |
2 ms |
1452 KB |
Output is correct |
5 |
Correct |
2 ms |
1512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3180 KB |
Output is correct |
2 |
Correct |
5 ms |
3108 KB |
Output is correct |
3 |
Correct |
5 ms |
3100 KB |
Output is correct |
4 |
Correct |
6 ms |
3100 KB |
Output is correct |
5 |
Correct |
5 ms |
3116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
292 KB |
Output is correct |
7 |
Correct |
0 ms |
296 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
292 KB |
Output is correct |
13 |
Correct |
0 ms |
296 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
2 ms |
1460 KB |
Output is correct |
17 |
Correct |
2 ms |
1492 KB |
Output is correct |
18 |
Correct |
3 ms |
1748 KB |
Output is correct |
19 |
Correct |
2 ms |
1452 KB |
Output is correct |
20 |
Correct |
2 ms |
1512 KB |
Output is correct |
21 |
Correct |
5 ms |
3180 KB |
Output is correct |
22 |
Correct |
5 ms |
3108 KB |
Output is correct |
23 |
Correct |
5 ms |
3100 KB |
Output is correct |
24 |
Correct |
6 ms |
3100 KB |
Output is correct |
25 |
Correct |
5 ms |
3116 KB |
Output is correct |
26 |
Correct |
6 ms |
3028 KB |
Output is correct |
27 |
Correct |
5 ms |
3136 KB |
Output is correct |
28 |
Correct |
6 ms |
3156 KB |
Output is correct |
29 |
Correct |
5 ms |
3156 KB |
Output is correct |
30 |
Correct |
5 ms |
3116 KB |
Output is correct |