#include <bits/stdc++.h>
using namespace std;
int m,n,d,k,ans;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> m >> n >> d >> k;
int a[m+2][n+2];
char c[m+1][n+1];
for(int i = 1;i <= m;i++) for(int j = 1;j <= n;j++) cin >> c[i][j];
for(int i = 0;i <= m;i++) for(int j = 0;j <= n;j++) a[i][j] = 0;
for(int i = 1;i <= m;i++) for(int j = 1;j <= n;j++) if(c[i][j]=='S')
a[max(1,i-d)][max(1,j-d)]++,a[min(m,i+d)+1][max(1,j-d)]--,a[max(1,i-d)][min(n,j+d)+1]--,a[min(m,i+d)+1][min(n,j+d)+1]++;
for(int i = 1;i <= m;i++) for(int j = 1;j <= n;j++) a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1];
for(int i = 1;i <= m;i++) for(int j = 1;j <= n;j++) if(c[i][j]=='M' and a[i][j]>=k) ans++;
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1536 KB |
Output is correct |
2 |
Correct |
9 ms |
1664 KB |
Output is correct |
3 |
Correct |
11 ms |
1792 KB |
Output is correct |
4 |
Correct |
9 ms |
1536 KB |
Output is correct |
5 |
Correct |
9 ms |
1664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
7040 KB |
Output is correct |
2 |
Correct |
17 ms |
6656 KB |
Output is correct |
3 |
Correct |
17 ms |
6400 KB |
Output is correct |
4 |
Correct |
19 ms |
7168 KB |
Output is correct |
5 |
Correct |
19 ms |
7040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
9 ms |
1536 KB |
Output is correct |
17 |
Correct |
9 ms |
1664 KB |
Output is correct |
18 |
Correct |
11 ms |
1792 KB |
Output is correct |
19 |
Correct |
9 ms |
1536 KB |
Output is correct |
20 |
Correct |
9 ms |
1664 KB |
Output is correct |
21 |
Correct |
19 ms |
7040 KB |
Output is correct |
22 |
Correct |
17 ms |
6656 KB |
Output is correct |
23 |
Correct |
17 ms |
6400 KB |
Output is correct |
24 |
Correct |
19 ms |
7168 KB |
Output is correct |
25 |
Correct |
19 ms |
7040 KB |
Output is correct |
26 |
Correct |
17 ms |
3456 KB |
Output is correct |
27 |
Correct |
17 ms |
3328 KB |
Output is correct |
28 |
Correct |
17 ms |
3328 KB |
Output is correct |
29 |
Correct |
16 ms |
3328 KB |
Output is correct |
30 |
Correct |
17 ms |
3328 KB |
Output is correct |