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;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, M, D, K;
cin >> N >> M >> D >> K;
vector<string> S(N);
for (int i = 0; i < N; i++) {
cin >> S[i];
}
vector pfs(N + 1, vector<int>(M + 1));
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
pfs[i + 1][j + 1] = pfs[i + 1][j] + pfs[i][j + 1] - pfs[i][j] + (S[i][j] == 'S');
}
}
int ans = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (S[i][j] == 'M') {
int x1 = max(0, i - D);
int x2 = min(N, i + D + 1);
int y1 = max(0, j - D);
int y2 = min(M, j + D + 1);
if (pfs[x2][y2] - pfs[x1][y2] - pfs[x2][y1] + pfs[x1][y1] >= K) {
ans++;
}
}
}
}
cout << ans << "\n";
return 6/22;
}
# | 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... |