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 r, c, d, k, h, nx1, nx2, ny1, ny2;
char t;
vector<pair<int, int> > mushrooms;
int main(){
cin >> r >> c >> d >> k;
int grid[r+5][c+5], sums[r+5][c+5];
memset(grid, 0, sizeof(grid));
memset(sums, 0, sizeof(sums));
for(int i = 1; i <= r; i++){
for(int j = 1; j <= c; j++){
cin >> t;
if(t == 'S') grid[i][j] = 1;
else if(t == 'M') mushrooms.push_back(make_pair(i, j));
}
}
for(int i = 1; i <= r; i++){
for(int j = 1; j <= c; j++){
sums[i][j] = sums[i-1][j] + sums[i][j-1] - sums[i-1][j-1] + grid[i][j];
}
}
for(int i = 0; i < mushrooms.size(); i++){
nx1 = max(1, mushrooms[i].first-d);
nx2 = min(r, mushrooms[i].first+d);
ny1 = max(1, mushrooms[i].second-d);
ny2 = min(c, mushrooms[i].second+d);
if((sums[nx2][ny2] - sums[nx1-1][ny2] - sums[nx2][ny1-1] + sums[nx1-1][ny1-1]) >= k) h++;
}
cout << h;
}
Compilation message (stderr)
mushrooms.cpp: In function 'int main()':
mushrooms.cpp:24:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < mushrooms.size(); i++){
~~^~~~~~~~~~~~~~~~~~
# | 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... |