#include <bits/stdc++.h>
using namespace std;
int r, c, d, k, out;
string s;
vector<vector<int>> sum;
vector<pair<int, int>> vp;
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> r >> c >> d >> k;
sum.assign(r+5, vector<int>(c+5, 0));// = vector<int>(r+5, vector<int>(c+5));
for (int i=0; i<r; i++) {
cin >> s;
for (int j=0; j<c; j++) {
if (s[j] == 'S') {
int x0=max(0, i+1-d), x1=min(r+1, i+1+d+1), y0=max(0, j+1-d), y1=min(c+1, j+1+d+1);
sum[x0][y0]++;
sum[x0][y1]--;
sum[x1][y0]--;
sum[x1][y1]++;
}
else if (s[j] == 'M') vp.push_back({i, j});
}
}
// for (int i=0; i<=r+1; i++) {for (int j=0; j<=c+1; j++) cout << sum[i][j] << ' '; cout << endl;}
for (int i=1; i<=r; i++) sum[i][0]+=sum[i-1][0];
for (int j=1; j<=c; j++) sum[0][j]+=sum[0][j-1];
for (int i=1; i<=r; i++) for (int j=1; j<=c; j++) sum[i][j]+=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
for (auto [x, y] : vp) if (sum[x+1][y+1] >= k) out++;
// for (int i=1; i<=r; i++) {for (int j=1; j<=c; j++) cout << sum[i][j] << ' '; cout << endl;}
cout << out;
return 0;
}
/*
5 5 1 1
....M
.M...
..S..
.S...
...M.
1 8 5 2
SM..MM.S
5 5 2 2
....M
.M...
..S..
.S...
...M.
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
324 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 |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
324 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 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 |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1108 KB |
Output is correct |
2 |
Correct |
2 ms |
1356 KB |
Output is correct |
3 |
Correct |
2 ms |
1484 KB |
Output is correct |
4 |
Correct |
2 ms |
1356 KB |
Output is correct |
5 |
Correct |
2 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
16128 KB |
Output is correct |
2 |
Correct |
19 ms |
19492 KB |
Output is correct |
3 |
Correct |
17 ms |
19580 KB |
Output is correct |
4 |
Correct |
17 ms |
16840 KB |
Output is correct |
5 |
Correct |
18 ms |
19468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
324 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 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 |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
452 KB |
Output is correct |
16 |
Correct |
2 ms |
1108 KB |
Output is correct |
17 |
Correct |
2 ms |
1356 KB |
Output is correct |
18 |
Correct |
2 ms |
1484 KB |
Output is correct |
19 |
Correct |
2 ms |
1356 KB |
Output is correct |
20 |
Correct |
2 ms |
1364 KB |
Output is correct |
21 |
Correct |
17 ms |
16128 KB |
Output is correct |
22 |
Correct |
19 ms |
19492 KB |
Output is correct |
23 |
Correct |
17 ms |
19580 KB |
Output is correct |
24 |
Correct |
17 ms |
16840 KB |
Output is correct |
25 |
Correct |
18 ms |
19468 KB |
Output is correct |
26 |
Correct |
9 ms |
5016 KB |
Output is correct |
27 |
Correct |
8 ms |
4856 KB |
Output is correct |
28 |
Correct |
7 ms |
4040 KB |
Output is correct |
29 |
Correct |
7 ms |
4180 KB |
Output is correct |
30 |
Correct |
10 ms |
5844 KB |
Output is correct |