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>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
using ll = long long;
const int N = 500'000 + 10;
int numRows, numCols, dist, cnt;
string s[N];
vector<vector<int>> pred;
int32_t main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr); std::cout.tie(nullptr);
cin >> numRows >> numCols >> dist >> cnt;
pred.resize(numRows + 5, vector<int>(numCols + 5, 0));
for (int i = 1; i <= numRows; ++ i) {
cin >> s[i]; s[i] = ' ' + s[i];
for (int j = 1; j <= numCols; ++ j) {
if (s[i][j] == 'S') {
int le = max(1, j - dist);
int ri = min(numCols, j + dist);
int up = max(1, i - dist);
int down = min(numRows, i + dist);
++ pred[up][le];
-- pred[up][ri + 1];
-- pred[down + 1][le];
++ pred[down + 1][ri + 1];
}
}
}
int res = 0;
for (int i = 1; i <= numRows; ++ i) {
for (int j = 1; j <= numCols; ++ j) {
pred[i][j] += pred[i - 1][j] + pred[i][j - 1] - pred[i - 1][j - 1];
if (s[i][j] == 'M' && pred[i][j] >= cnt) ++ res;
}
}
cout << res;
return (0 ^ 0);
}
/// Code by vuavisao
# | 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... |