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 main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int r,c,d,k;
cin>>r>>c>>d>>k;
vector<pair<int,int> > mushrooms;
int arr[r+1][c+1];
int diff[r+2][c+2];
memset(arr,0,sizeof(arr));
memset(diff,0,sizeof(diff));
for (int i=1;i<=r;i++){
for (int j=1;j<=c;j++){
char x;
cin>>x;
if (x=='M') mushrooms.push_back(make_pair(i,j));
else if (x=='S') {
int a=max(i-d,1);
int b=max(j-d,1);
int e=min(i+d,r)+1;
int f=min(j+d,c)+1;
diff[a][b]++;
diff[a][f]--;
diff[e][b]--;
diff[e][f]++;
}
}
}
for (int i=1;i<=r;i++){
for (int j=1;j<=c;j++){
arr[i][j]=arr[i][j-1]+arr[i-1][j]-arr[i-1][j-1]+diff[i][j];
}
}
int total=0;
for (int i=0;i<mushrooms.size();i++){
int x=mushrooms[i].first;
int y=mushrooms[i].second;
if (arr[x][y]>=k) total++;
}
cout<<total;
}
Compilation message (stderr)
mushrooms.cpp: In function 'int main()':
mushrooms.cpp:36: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... |