#include <bits/stdc++.h>
using namespace std;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, d, k;
cin >> n >> m >> d >> k;
string tb[n + 1];
int pf[n + 1][m + 1];
memset(pf, 0, sizeof pf);
for(int i = 1;i<=n;i++){
cin >> tb[i];
tb[i] = " " + tb[i];
for(int j = 1;j<=m;j++){
pf[i][j] = (tb[i][j] == 'S') + pf[i - 1][j] + pf[i][j - 1] - pf[i - 1][j - 1];
}
}
int ans = 0;
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
if(tb[i][j] == 'M'){
int top = min(n, i + d), bt = max(1, i - d), r = min(m, j + d), l = max(1, j - d);
if(pf[top][r] - pf[top][l - 1] - pf[bt - 1][r] + pf[bt - 1][l - 1] >= k) ++ans;
}
}
}
cout << ans;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |