#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int r, c, d, s;
cin >> r >> c >> d >> s;
vector<vector<char>> a(r + 5, vector<char>(c + 5));
for (int i = 1; i <= r; ++i) {
for (int j = 1; j <= c; ++j) {
cin >> a[i][j];
}
}
vector<vector<int>> pre(r + 5, vector<int>(c + 5));
for (int i = 1; i <= r; ++i) {
for (int j = 1; j <= c; ++j) {
pre[i][j] = pre[i - 1][j] + pre[i][j - 1] - pre[i - 1][j - 1];
if (a[i][j] == 'S') {
++pre[i][j];
}
}
}
auto f = [&](int lx, int ly, int rx, int ry) -> int {
return pre[rx][ry] - pre[rx][ly - 1] - pre[lx - 1][ry] + pre[lx - 1][ly - 1];
};
int ans = 0;
for (int i = 1; i <= r; ++i) {
for (int j = 1; j <= c; ++j) {
if (a[i][j] == 'M' && f(max(i - d, 1LL), max(j - d, 1LL), min(i + d, r), min(j + d, c)) >= s) {
++ans;
}
}
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
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 |
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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 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 |
344 KB |
Output is correct |
2 |
Correct |
0 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 |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2140 KB |
Output is correct |
2 |
Correct |
3 ms |
2140 KB |
Output is correct |
3 |
Correct |
3 ms |
2652 KB |
Output is correct |
4 |
Correct |
3 ms |
2332 KB |
Output is correct |
5 |
Correct |
3 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
30832 KB |
Output is correct |
2 |
Correct |
15 ms |
30832 KB |
Output is correct |
3 |
Correct |
17 ms |
30576 KB |
Output is correct |
4 |
Correct |
17 ms |
30644 KB |
Output is correct |
5 |
Correct |
16 ms |
30832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 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 |
344 KB |
Output is correct |
12 |
Correct |
0 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 |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
2140 KB |
Output is correct |
17 |
Correct |
3 ms |
2140 KB |
Output is correct |
18 |
Correct |
3 ms |
2652 KB |
Output is correct |
19 |
Correct |
3 ms |
2332 KB |
Output is correct |
20 |
Correct |
3 ms |
2396 KB |
Output is correct |
21 |
Correct |
16 ms |
30832 KB |
Output is correct |
22 |
Correct |
15 ms |
30832 KB |
Output is correct |
23 |
Correct |
17 ms |
30576 KB |
Output is correct |
24 |
Correct |
17 ms |
30644 KB |
Output is correct |
25 |
Correct |
16 ms |
30832 KB |
Output is correct |
26 |
Correct |
12 ms |
7516 KB |
Output is correct |
27 |
Correct |
7 ms |
4956 KB |
Output is correct |
28 |
Correct |
8 ms |
5468 KB |
Output is correct |
29 |
Correct |
8 ms |
5360 KB |
Output is correct |
30 |
Correct |
10 ms |
6480 KB |
Output is correct |