#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
int r,c,d,k;
cin>>r>>c>>d>>k;
vector<vector<char>> g(r+1,vector<char>(c+2));
vector<vector<int>> prefix(r+2,vector<int>(c+2));
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
cin>>g[i][j];
if(g[i][j]=='S'){
int one=1;
int start_x=max(one,i-d),start_y=max(one,j-d);
int end_x=min(r+1,i+d+1),end_y=min(c+1,j+d+1);
//cout<<start_x<<" "<<start_y<<" "<<end_x<<" "<<end_y<<endl;
prefix[start_x][start_y]++;
prefix[end_x][end_y]++;
prefix[start_x][end_y]--;
prefix[end_x][start_y]--;
}
}
}
for(int i=0;i<=r;i++){
for(int j=0;j<=c;j++){
if(i>0)prefix[i][j]+=prefix[i-1][j];
if(j>0)prefix[i][j]+=prefix[i][j-1];
if(j>0&&i>0)prefix[i][j]-=prefix[i-1][j-1];
}
}
int ans=0;
for(int i=0;i<=r;i++){
for(int j=0;j<=c;j++){
//if(g[i][j]=='M')
//cout<<"( "<<prefix[i][j]<<","<<i<<", "<<j<<" )"<<"\t";
if(prefix[i][j]>=k&&g[i][j]=='M')
{
ans++;
}
//cout<<"( "<<prefix[i][j]<<","<<i<<", "<<j<<" )"<<"\t";
//cout<<prefix[i][j]<<"\t";
}
//cout<<endl;
}
cout<<ans<<endl;
}
signed main(){
cin.tie(NULL);
cout.tie(NULL);
//setIO("paintbarn");
ios_base::sync_with_stdio(NULL);
int t=1;
//cin>>t;
while(t--)solve();
return 0;
}
/*
4 4 4 1
....
.M..
..MM
...S
_____
5 5 1 1
....M
.M...
..S..
.S...
...M.
______
1 8 5 2
SM..MM.S
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1996 KB |
Output is correct |
2 |
Correct |
5 ms |
2340 KB |
Output is correct |
3 |
Correct |
6 ms |
2820 KB |
Output is correct |
4 |
Correct |
5 ms |
2380 KB |
Output is correct |
5 |
Correct |
7 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
16864 KB |
Output is correct |
2 |
Correct |
20 ms |
16940 KB |
Output is correct |
3 |
Correct |
19 ms |
16992 KB |
Output is correct |
4 |
Correct |
21 ms |
16992 KB |
Output is correct |
5 |
Correct |
21 ms |
16908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
5 ms |
1996 KB |
Output is correct |
17 |
Correct |
5 ms |
2340 KB |
Output is correct |
18 |
Correct |
6 ms |
2820 KB |
Output is correct |
19 |
Correct |
5 ms |
2380 KB |
Output is correct |
20 |
Correct |
7 ms |
2392 KB |
Output is correct |
21 |
Correct |
20 ms |
16864 KB |
Output is correct |
22 |
Correct |
20 ms |
16940 KB |
Output is correct |
23 |
Correct |
19 ms |
16992 KB |
Output is correct |
24 |
Correct |
21 ms |
16992 KB |
Output is correct |
25 |
Correct |
21 ms |
16908 KB |
Output is correct |
26 |
Correct |
22 ms |
7180 KB |
Output is correct |
27 |
Correct |
13 ms |
5180 KB |
Output is correct |
28 |
Correct |
15 ms |
5444 KB |
Output is correct |
29 |
Correct |
14 ms |
5312 KB |
Output is correct |
30 |
Correct |
15 ms |
6492 KB |
Output is correct |