#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
using namespace std;
#define sped_up ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
const ll INF = (ll)1e9 + 1, INFL = (ll)1e18 + 1;
const ll mod = (ll)1e9 + 7, MAXN = (ll)2e5 + 1;
int main () {
sped_up;
ll n, m, d, x;
cin >> n >> m >> d >> x;
ll cnt = 0;
ll t[n + 2][m + 2];
char a[n + 2][m + 2];
for (int i = 0; i <= n + 1; i++) {
for (int j = 0; j <= m + 1; j++) {
t[i][j] = 0;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
if (a[i][j] == 'S') {
t[max(1ll, i - d)][max(1ll, j - d)]++;
t[max(1ll, i - d)][min(m + 1, j + d + 1)]--;
t[min(n + 1, i + d + 1)][max(1ll, j - d)]--;
t[min(n + 1, i + d + 1)][min(m + 1, j + d + 1)]++;
}
}
}
for (int i = 1; i <= n + 1; i++) {
for (int j = 1; j <= m + 1; j++) {
t[i][j] += t[i][j - 1];
}
}
for (int i = 1; i <= n + 1; i++) {
for (int j = 1; j <= m + 1; j++) {
t[i][j] += t[i - 1][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i][j] == 'M' && t[i][j] >= x) cnt++;
}
}
cout << cnt;
}
# | 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... |