#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
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 |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
632 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2168 KB |
Output is correct |
2 |
Correct |
7 ms |
2168 KB |
Output is correct |
3 |
Correct |
8 ms |
2552 KB |
Output is correct |
4 |
Correct |
7 ms |
2168 KB |
Output is correct |
5 |
Correct |
8 ms |
2320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
12660 KB |
Output is correct |
2 |
Correct |
29 ms |
14828 KB |
Output is correct |
3 |
Correct |
29 ms |
14824 KB |
Output is correct |
4 |
Correct |
28 ms |
12796 KB |
Output is correct |
5 |
Correct |
29 ms |
14824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
632 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
504 KB |
Output is correct |
16 |
Correct |
7 ms |
2168 KB |
Output is correct |
17 |
Correct |
7 ms |
2168 KB |
Output is correct |
18 |
Correct |
8 ms |
2552 KB |
Output is correct |
19 |
Correct |
7 ms |
2168 KB |
Output is correct |
20 |
Correct |
8 ms |
2320 KB |
Output is correct |
21 |
Correct |
26 ms |
12660 KB |
Output is correct |
22 |
Correct |
29 ms |
14828 KB |
Output is correct |
23 |
Correct |
29 ms |
14824 KB |
Output is correct |
24 |
Correct |
28 ms |
12796 KB |
Output is correct |
25 |
Correct |
29 ms |
14824 KB |
Output is correct |
26 |
Correct |
19 ms |
6000 KB |
Output is correct |
27 |
Correct |
21 ms |
6764 KB |
Output is correct |
28 |
Correct |
18 ms |
5876 KB |
Output is correct |
29 |
Correct |
19 ms |
6000 KB |
Output is correct |
30 |
Correct |
20 ms |
7024 KB |
Output is correct |