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() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m, k, d;
cin >> n >> m >> d >> k;
vector<vector<char>> a(n + 2, vector<char>(n + 2));
vector<vector<int>> qs(n + 2, vector<int>(n + 2, 0));
for (int i = 1;i <= n;i++) for (int j = 1;j <= m;j++) {
cin >> a[i][j];
if (a[i][j] == 'S') {
qs[max(1, i - d)][max(1, j - d)]++;
qs[max(1, i - d)][min(n + 1, j + d + 1)]--;
qs[min(n + 1, i + d + 1)][max(1, j - d)]--;
qs[min(n + 1, i + d + 1)][min(n + 1, j + d + 1)]++;
}
}
int ans = 0;
for (int i = 1;i <= n;i++) {
for (int j = 1;j <= m;j++) {
qs[i][j] += qs[i - 1][j] + qs[i][j - 1] - qs[i - 1][j - 1];
if (a[i][j] == 'M' && qs[i][j] >= k) ans++;
}
}
cout << ans;
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... |