#include <bits/stdc++.h>
using namespace std;
int main() {
int R,C,D,S;
cin >> R >> C >> D >> S;
string grid[R];
int pref[R+1][C+1];
memset(pref,0,sizeof(pref));
for(int i=0;i<R;i++){
cin >> grid[i];
for(int j=0;j<C;j++){
if(grid[i][j] == 'S'){
int a = max(0,i-D);
int b = min(i+D+1,R);
int c = max(0,j-D);
int d = min(j+D+1,C);
pref[a][c]++;
pref[a][d]--;
pref[b][c]--;
pref[b][d]++;
}
}
}
for(int i=0;i<R;i++){
for(int j=0;j<C;j++){
if(i > 0){
pref[i][j] += pref[i-1][j];
}
if(j > 0){
pref[i][j] += pref[i][j-1];
}
if(i > 0 && j > 0){
pref[i][j] -= pref[i-1][j-1];
}
}
}
int ans = 0;
for(int i=0;i<R;i++){
for(int j=0;j<C;j++){
if(grid[i][j] == 'M' && pref[i][j] >= S){
ans++;
}
}
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1372 KB |
Output is correct |
2 |
Correct |
4 ms |
1372 KB |
Output is correct |
3 |
Correct |
4 ms |
1884 KB |
Output is correct |
4 |
Correct |
4 ms |
1628 KB |
Output is correct |
5 |
Correct |
4 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
5368 KB |
Output is correct |
2 |
Correct |
10 ms |
5384 KB |
Output is correct |
3 |
Correct |
10 ms |
5620 KB |
Output is correct |
4 |
Correct |
11 ms |
5372 KB |
Output is correct |
5 |
Correct |
10 ms |
5420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
1372 KB |
Output is correct |
17 |
Correct |
4 ms |
1372 KB |
Output is correct |
18 |
Correct |
4 ms |
1884 KB |
Output is correct |
19 |
Correct |
4 ms |
1628 KB |
Output is correct |
20 |
Correct |
4 ms |
1372 KB |
Output is correct |
21 |
Correct |
11 ms |
5368 KB |
Output is correct |
22 |
Correct |
10 ms |
5384 KB |
Output is correct |
23 |
Correct |
10 ms |
5620 KB |
Output is correct |
24 |
Correct |
11 ms |
5372 KB |
Output is correct |
25 |
Correct |
10 ms |
5420 KB |
Output is correct |
26 |
Correct |
14 ms |
4188 KB |
Output is correct |
27 |
Correct |
9 ms |
3164 KB |
Output is correct |
28 |
Correct |
10 ms |
2836 KB |
Output is correct |
29 |
Correct |
13 ms |
2908 KB |
Output is correct |
30 |
Correct |
12 ms |
3932 KB |
Output is correct |