#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, m, d, k;
vector<pair<ll,ll>> v;
int main(){
cin >> n >> m >> d >> k;
ll pfs[n + 5][m + 5];
for(int i = 0; i <= n; i++){
for(int j = 0; j <= m; j++){
pfs[i][j] = 0;
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
char c;
cin >> c;
pfs[i][j] = pfs[i - 1][j] + pfs[i][j - 1] - pfs[i - 1][j - 1];
if(c == 'S'){
pfs[i][j]++;
}
if(c == 'M'){
v.push_back({i, j});
}
}
}
ll res = 0;
for(int i = 0; i < v.size(); i++){
ll temp = 0;
ll x = v[i].first;
ll y = v[i].second;
ll a = x;
ll b = y;
x = min(x + d, n);
y = min(y + d, m);
a = max(1LL, a - d);
b = max(1LL, b - d);
temp = pfs[x][y] + pfs[a - 1][b - 1] - pfs[x][b - 1] - pfs[a - 1][y];
if(temp >= k){
res++;
}
}
cout << res;
}
# | 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... |