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;
int main() {
int n, m, d, k, ans = 0;
cin >> n >> m >> d >> k;
char mat[n+1][m+1];
int P[n+2][m+2];
memset(P, 0, sizeof(P));
for(int i=1; i<=n; i++) {
for(int j=1; j<=m; j++) {
cin >> mat[i][j];
if(mat[i][j] == 'S') {
int x1 = max(1, i - d), x2 = min(n, i + d), y1 = max(1, j - d), y2 = min(m, j + d);
P[x1][y1]++; P[x2+1][y2+1]++;
P[x1][y2+1]--, P[x2+1][y1]--;
}
}
}
for(int i=1; i<=n; i++) {
for(int j=1; j<=m; j++) {
P[i][j] += P[i-1][j] + P[i][j-1];
P[i][j] -= P[i-1][j-1];
if(P[i][j] >= k && mat[i][j] == 'M') ans++;
}
}
cout << ans << '\n';
return 0;
}
# | 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... |