This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int X = 2e5 + 5;
int n, m, d, k;
int main() {
cin >> n >> m >> d >> k;
int pref[n + 5][m + 5];
char c[n + 5][m + 5];
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
cin >> c[i][j];
pref[i][j] = (c[i][j] == 'S') + pref[i-1][j] + pref[i][j-1] - pref[i-1][j-1];
}
}
int ans = 0;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(c[i][j] != 'M') continue;
int cnt = pref[min(n, i+d)][min(m, j+d)] - pref[max(0, i-d-1)][min(m, j+d)] - pref[min(n, i+d)][max(0, j-d-1)] + pref[max(0, i-d-1)][max(0, j-d-1)];
if(cnt >= k) ans++;
}
}
cout << ans << endl;
}
# | 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... |