#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, m, d, k, pfs[1005][1005];
vector<pair<ll,ll>> v;
int main(){
cin >> n >> m >> d >> k;
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 x = v[i].first;
ll y = v[i].second;
ll temp = 0;
x += d;
y += d;
if(x > n){
x = n;
}
if(y > m){
y = m;
}
ll a = v[i].first;
ll b = v[i].second;
a -= d;
b -= d;
if(a < 1){
a = 1;
}
if(b < 1){
b = 1;
}
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... |