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 <iostream>
#include <tuple>
#include <vector>
using namespace std;
#define f first
#define s second
int r, c, d, k, ans, spr, r1, r2, c1, c2;
vector<pair<int, int>> mushrooms;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> r >> c >> d >> k;
vector<vector<int>> grid(r + 5, vector<int> (c + 5, 0));
vector<vector<int>> pref(r + 5, vector<int> (c + 5, 0));
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
char x; cin >> x;
if (x == 'M') {
mushrooms.push_back({i, j});
} else if (x == 'S') {
grid[i][j] = 1;
}
}
}
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
pref[i][j] = pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1] + grid[i][j];
}
}
for (pair<int, int> p : mushrooms) {
r1 = (p.f + d >= r ? r : p.f + d);
c1 = (p.s + d >= c ? c : p.s + d);
r2 = (p.f - d - 1 >= 0 ? p.f - d - 1 : 0);
c2 = (p.s - d - 1 >= 0 ? p.s - d - 1 : 0);
spr = pref[r1][c1] - pref[r1][c2] - pref[r2][c1] + pref[r2][c2];
if (spr >= k) ans++;
}
cout << ans << "\n";
}
# | 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... |