#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
int R, C;
cin >>R>>C;
int D, K;
cin >>D >>K;
vector <vector <int>> pref(R+1, vector <int> (C+1,0));
vector <pair<int,int>> loc;
for(int i=1; i<=R; i++){
string a;
cin >>a;
for(int j=1; j<=C; j++){
char x = a[j-1];
pref[i][j]=pref[i][j-1]+pref[i-1][j]-pref[i-1][j-1];
if(x=='M') loc.push_back(make_pair(i,j));
if(x=='S'){
pref[i][j]++;
}
}
}
int ans = 0;
for(auto x: loc){
pair maxpos =make_pair(min(R,x.first+D), min(C,x.second+D));
pair minpos =make_pair(max(1ll,x.first-D), max(1ll,x.second-D));
int n = pref[maxpos.first][maxpos.second]-pref[minpos.first-1][maxpos.second]-pref[maxpos.first][minpos.second-1]+pref[minpos.first-1][minpos.second-1];
if(K<=n) ans++;
}
cout <<ans<<endl;
}
signed main(){
int t=1;
while(t--){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
0 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1924 KB |
Output is correct |
2 |
Correct |
7 ms |
2028 KB |
Output is correct |
3 |
Correct |
10 ms |
2528 KB |
Output is correct |
4 |
Correct |
7 ms |
2132 KB |
Output is correct |
5 |
Correct |
8 ms |
2144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
16176 KB |
Output is correct |
2 |
Correct |
28 ms |
21768 KB |
Output is correct |
3 |
Correct |
26 ms |
21776 KB |
Output is correct |
4 |
Correct |
25 ms |
16748 KB |
Output is correct |
5 |
Correct |
27 ms |
21904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
0 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
6 ms |
1924 KB |
Output is correct |
17 |
Correct |
7 ms |
2028 KB |
Output is correct |
18 |
Correct |
10 ms |
2528 KB |
Output is correct |
19 |
Correct |
7 ms |
2132 KB |
Output is correct |
20 |
Correct |
8 ms |
2144 KB |
Output is correct |
21 |
Correct |
23 ms |
16176 KB |
Output is correct |
22 |
Correct |
28 ms |
21768 KB |
Output is correct |
23 |
Correct |
26 ms |
21776 KB |
Output is correct |
24 |
Correct |
25 ms |
16748 KB |
Output is correct |
25 |
Correct |
27 ms |
21904 KB |
Output is correct |
26 |
Correct |
22 ms |
7452 KB |
Output is correct |
27 |
Correct |
20 ms |
8768 KB |
Output is correct |
28 |
Correct |
17 ms |
6924 KB |
Output is correct |
29 |
Correct |
16 ms |
6992 KB |
Output is correct |
30 |
Correct |
24 ms |
9556 KB |
Output is correct |