#include <bits/stdc++.h>
using namespace std;
int main(){
cin.tie(NULL)->sync_with_stdio(false);
int n,m,d,k; cin >> n >> m >> d >> k;
char mp[n+5][m+5];
int v[n+5][m+5],qs[n+5][m+5];
for(int i=0 ; i<=n ; i++){
for(int j=0 ; j<=m ; j++){
v[i][j]=0;
qs[i][j]=0;
}
}
int ans=0;
for(int i=1 ; i<=n ; i++){
for(int j=1 ; j<=m ; j++){
cin >> mp[i][j];
}
}
for(int i=1 ; i<=n ; i++){
for(int j=1 ; j<=m ; j++){
if(mp[i][j]=='S'){
v[max(1,i-d)][max(1,j-d)]++;
if(j+d+1<=m) v[max(1,i-d)][j+d+1]--;
if(i+d+1<=n) v[i+d+1][max(1,j-d)]--;
if(i+d+1<=n && j+d+1<=m) v[i+d+1][j+d+1]++;
}
}
}
for(int i=1 ; i<=n ; i++){
for(int j=1 ; j<=m ; j++){
qs[i][j]=qs[i-1][j]+qs[i][j-1]-qs[i-1][j-1]+v[i][j];
}
}
for(int i=1 ; i<=n ; i++){
for(int j=1 ; j<=m ; j++){
if(mp[i][j]=='M'){
if(qs[i][j]>=k) ans++;
}
}
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
356 KB |
Output is correct |
3 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
356 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2140 KB |
Output is correct |
2 |
Correct |
4 ms |
2140 KB |
Output is correct |
3 |
Correct |
7 ms |
2904 KB |
Output is correct |
4 |
Correct |
3 ms |
2396 KB |
Output is correct |
5 |
Correct |
5 ms |
2512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
26712 KB |
Output is correct |
2 |
Correct |
20 ms |
26716 KB |
Output is correct |
3 |
Correct |
24 ms |
27212 KB |
Output is correct |
4 |
Correct |
22 ms |
27228 KB |
Output is correct |
5 |
Correct |
22 ms |
27224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
356 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
3 ms |
2140 KB |
Output is correct |
17 |
Correct |
4 ms |
2140 KB |
Output is correct |
18 |
Correct |
7 ms |
2904 KB |
Output is correct |
19 |
Correct |
3 ms |
2396 KB |
Output is correct |
20 |
Correct |
5 ms |
2512 KB |
Output is correct |
21 |
Correct |
24 ms |
26712 KB |
Output is correct |
22 |
Correct |
20 ms |
26716 KB |
Output is correct |
23 |
Correct |
24 ms |
27212 KB |
Output is correct |
24 |
Correct |
22 ms |
27228 KB |
Output is correct |
25 |
Correct |
22 ms |
27224 KB |
Output is correct |
26 |
Correct |
11 ms |
6052 KB |
Output is correct |
27 |
Correct |
11 ms |
5208 KB |
Output is correct |
28 |
Correct |
11 ms |
5724 KB |
Output is correct |
29 |
Correct |
10 ms |
5800 KB |
Output is correct |
30 |
Correct |
15 ms |
5724 KB |
Output is correct |