#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> > mushroom;
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int r,c,d,k;
cin >> r >> c >> d >> k;
char arr[r+5][c+5];
int pref[r+5][c+5];
memset(pref,0,sizeof(pref));
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
cin >> arr[i][j];
if(arr[i][j]=='S')pref[i][j]++;
if(i)pref[i][j]+=pref[i-1][j];
if(j)pref[i][j]+=pref[i][j-1];
if(i&&j)pref[i][j]-=pref[i-1][j-1];
if(arr[i][j]=='M')mushroom.push_back({i,j});
}
}
int ans=0;
for(auto p : mushroom){
//area nya itu p.first-d p.second
int kananx=min(p.first+d,r),kanany=min(p.second+d,c),kirix=max(p.first-d,1),kiriy=max(p.second-d,1);
int many=pref[kananx][kanany]-pref[kirix-1][kanany]-pref[kananx][kiriy-1]+pref[kirix-1][kiriy-1];
if(many>=k)ans++;
}
cout << ans << endl;
return 0;
}
# |
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 |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
504 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 |
636 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 |
6 ms |
1528 KB |
Output is correct |
2 |
Correct |
7 ms |
1592 KB |
Output is correct |
3 |
Correct |
7 ms |
1784 KB |
Output is correct |
4 |
Correct |
6 ms |
1500 KB |
Output is correct |
5 |
Correct |
7 ms |
1656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
14836 KB |
Output is correct |
2 |
Correct |
35 ms |
17128 KB |
Output is correct |
3 |
Correct |
31 ms |
17168 KB |
Output is correct |
4 |
Correct |
31 ms |
15088 KB |
Output is correct |
5 |
Correct |
38 ms |
17128 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 |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
504 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 |
636 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
504 KB |
Output is correct |
16 |
Correct |
6 ms |
1528 KB |
Output is correct |
17 |
Correct |
7 ms |
1592 KB |
Output is correct |
18 |
Correct |
7 ms |
1784 KB |
Output is correct |
19 |
Correct |
6 ms |
1500 KB |
Output is correct |
20 |
Correct |
7 ms |
1656 KB |
Output is correct |
21 |
Correct |
27 ms |
14836 KB |
Output is correct |
22 |
Correct |
35 ms |
17128 KB |
Output is correct |
23 |
Correct |
31 ms |
17168 KB |
Output is correct |
24 |
Correct |
31 ms |
15088 KB |
Output is correct |
25 |
Correct |
38 ms |
17128 KB |
Output is correct |
26 |
Correct |
18 ms |
4844 KB |
Output is correct |
27 |
Correct |
19 ms |
5220 KB |
Output is correct |
28 |
Correct |
18 ms |
4520 KB |
Output is correct |
29 |
Correct |
17 ms |
4568 KB |
Output is correct |
30 |
Correct |
19 ms |
5744 KB |
Output is correct |