#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,m,d,k;
cin>>n>>m>>d>>k;
char arr[n+5][m+5];
int pre[n+5][m+5];
int fores[n+5][m+5];
memset(pre,0,sizeof pre);
memset(fores,0,sizeof fores);
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
char a;
cin>>a;
arr[i][j] = a;
if(a=='S'){
fores[i][j]++;
}
}
}
pre[1][1] = fores[1][1];
for(int i = 2;i<=m;i++)
pre[1][i]=pre[1][i-1]+fores[1][i];
for(int i = 2;i<=n;i++)
pre[i][1]=pre[i-1][1]+fores[i][1];
for(int i=2;i<=n;i++){
for(int j=2;j<=m;j++){
pre[i][j]=pre[i-1][j]+pre[i][j-1]-pre[i-1][j-1]+fores[i][j];
}
}
int ans=0;
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
if(arr[i][j]=='M'){
long long x1 = max(i-d,1) , y1 = max(j-d,1) , x2 = min(i+d,n) , y2 = min(j+d,m);
long long sum = pre[x2][y2];
if(x1>1)sum-=pre[x1-1][y2];
if(y1>1)sum-=pre[x2][y1-1];
if(x1>1&&y1>1)sum+=pre[x1-1][y1-1];
if(sum>=k)ans++;
}
}
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2088 KB |
Output is correct |
2 |
Correct |
5 ms |
2132 KB |
Output is correct |
3 |
Correct |
6 ms |
2516 KB |
Output is correct |
4 |
Correct |
5 ms |
2168 KB |
Output is correct |
5 |
Correct |
5 ms |
2260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
26708 KB |
Output is correct |
2 |
Correct |
21 ms |
26736 KB |
Output is correct |
3 |
Correct |
21 ms |
26632 KB |
Output is correct |
4 |
Correct |
23 ms |
26728 KB |
Output is correct |
5 |
Correct |
24 ms |
26708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
5 ms |
2088 KB |
Output is correct |
17 |
Correct |
5 ms |
2132 KB |
Output is correct |
18 |
Correct |
6 ms |
2516 KB |
Output is correct |
19 |
Correct |
5 ms |
2168 KB |
Output is correct |
20 |
Correct |
5 ms |
2260 KB |
Output is correct |
21 |
Correct |
22 ms |
26708 KB |
Output is correct |
22 |
Correct |
21 ms |
26736 KB |
Output is correct |
23 |
Correct |
21 ms |
26632 KB |
Output is correct |
24 |
Correct |
23 ms |
26728 KB |
Output is correct |
25 |
Correct |
24 ms |
26708 KB |
Output is correct |
26 |
Correct |
12 ms |
5576 KB |
Output is correct |
27 |
Correct |
13 ms |
4820 KB |
Output is correct |
28 |
Correct |
13 ms |
5204 KB |
Output is correct |
29 |
Correct |
14 ms |
5168 KB |
Output is correct |
30 |
Correct |
16 ms |
5312 KB |
Output is correct |