#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define pll pair<ll, ll>
using namespace std;
int main(){
ll r, c, d, k;
cin >> r >> c >> d >> k;
ll pref[r+10][c+10];
memset(pref, 0, sizeof(pref));
vector<pll>mushroom;
for(int i=1; i<=r; i++){
for(int j=1; j<=c; j++){
char g; cin >> g;
if(g=='M') mushroom.pb({i, j});
pref[i][j]=pref[i-1][j]+pref[i][j-1]-pref[i-1][j-1]+(g=='S');
}
}
ll ans=0;
for(auto i : mushroom){
ll a, b, x, y;
// cout << i.fi << " " << i.se << endl;
a=max(1ll, i.fi-d);
b=max(1ll, i.se-d);
x=min(r, i.fi+d);
y=min(c, i.se+d);
// cout << a << b << " " << x << y << endl;
ll tot = pref[x][y]-pref[a-1][y]-pref[x][b-1]+pref[a-1][b-1];
if(tot>=k) ans++;
}
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
432 KB |
Output is correct |
3 |
Correct |
1 ms |
436 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
432 KB |
Output is correct |
3 |
Correct |
1 ms |
436 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
696 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2116 KB |
Output is correct |
2 |
Correct |
8 ms |
2068 KB |
Output is correct |
3 |
Correct |
9 ms |
2516 KB |
Output is correct |
4 |
Correct |
8 ms |
2076 KB |
Output is correct |
5 |
Correct |
8 ms |
2260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
47884 KB |
Output is correct |
2 |
Correct |
42 ms |
52132 KB |
Output is correct |
3 |
Correct |
41 ms |
52088 KB |
Output is correct |
4 |
Correct |
39 ms |
47988 KB |
Output is correct |
5 |
Correct |
42 ms |
52152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
432 KB |
Output is correct |
3 |
Correct |
1 ms |
436 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
696 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
560 KB |
Output is correct |
16 |
Correct |
8 ms |
2116 KB |
Output is correct |
17 |
Correct |
8 ms |
2068 KB |
Output is correct |
18 |
Correct |
9 ms |
2516 KB |
Output is correct |
19 |
Correct |
8 ms |
2076 KB |
Output is correct |
20 |
Correct |
8 ms |
2260 KB |
Output is correct |
21 |
Correct |
38 ms |
47884 KB |
Output is correct |
22 |
Correct |
42 ms |
52132 KB |
Output is correct |
23 |
Correct |
41 ms |
52088 KB |
Output is correct |
24 |
Correct |
39 ms |
47988 KB |
Output is correct |
25 |
Correct |
42 ms |
52152 KB |
Output is correct |
26 |
Correct |
22 ms |
8408 KB |
Output is correct |
27 |
Correct |
28 ms |
8992 KB |
Output is correct |
28 |
Correct |
25 ms |
7824 KB |
Output is correct |
29 |
Correct |
21 ms |
7700 KB |
Output is correct |
30 |
Correct |
23 ms |
10052 KB |
Output is correct |