#include <bits/stdc++.h>
using namespace std;
int r,c,d,k;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> r >> c >> d >> k;
int arr[r+5][c+5];
int pref[r+5][c+5];
memset(arr,0,sizeof(arr));
memset(pref,0,sizeof(pref));
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
char x;
cin >> x;
if(x == '.') arr[i][j] = 0;
else if(x == 'M') arr[i][j] = 1;
else arr[i][j] = 2;
}
}
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
if(arr[i][j] == 2){
pref[max(i-d,1)][max(j-d,1)]++;
pref[max(i-d,1)][min(j+d+1,c+1)]--;
pref[min((i+d+1),r+1)][max(j-d,1)]--;
pref[min((i+d+1),r+1)][min(j+d+1,c+1)]++;
}
}
}
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
pref[i][j]+=pref[i-1][j]+pref[i][j-1]-pref[i-1][j-1];
}
}
int ans=0;
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
// cout<<pref[i][j]<<" ";
ans+=(pref[i][j]>=k&&arr[i][j]==1);
}
// cout<<endl;
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1996 KB |
Output is correct |
2 |
Correct |
5 ms |
2116 KB |
Output is correct |
3 |
Correct |
9 ms |
2552 KB |
Output is correct |
4 |
Correct |
7 ms |
2124 KB |
Output is correct |
5 |
Correct |
5 ms |
2252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
24268 KB |
Output is correct |
2 |
Correct |
22 ms |
24152 KB |
Output is correct |
3 |
Correct |
23 ms |
24284 KB |
Output is correct |
4 |
Correct |
27 ms |
24188 KB |
Output is correct |
5 |
Correct |
24 ms |
24208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
5 ms |
1996 KB |
Output is correct |
17 |
Correct |
5 ms |
2116 KB |
Output is correct |
18 |
Correct |
9 ms |
2552 KB |
Output is correct |
19 |
Correct |
7 ms |
2124 KB |
Output is correct |
20 |
Correct |
5 ms |
2252 KB |
Output is correct |
21 |
Correct |
28 ms |
24268 KB |
Output is correct |
22 |
Correct |
22 ms |
24152 KB |
Output is correct |
23 |
Correct |
23 ms |
24284 KB |
Output is correct |
24 |
Correct |
27 ms |
24188 KB |
Output is correct |
25 |
Correct |
24 ms |
24208 KB |
Output is correct |
26 |
Correct |
18 ms |
5448 KB |
Output is correct |
27 |
Correct |
16 ms |
4672 KB |
Output is correct |
28 |
Correct |
15 ms |
5068 KB |
Output is correct |
29 |
Correct |
15 ms |
5108 KB |
Output is correct |
30 |
Correct |
14 ms |
5236 KB |
Output is correct |