#include <iostream>
#include <tuple>
#include <vector>
using namespace std;
#define f first
#define s second
int r, c, d, k, ans, spr, r1, r2, c1, c2;
vector<pair<int, int>> mushrooms;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> r >> c >> d >> k;
vector<vector<int>> grid(r + 5, vector<int> (c + 5, 0));
vector<vector<int>> pref(r + 5, vector<int> (c + 5, 0));
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
char x; cin >> x;
if (x == 'M') {
mushrooms.push_back({i, j});
} else if (x == 'S') {
grid[i][j] = 1;
}
}
}
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
pref[i][j] = pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1] + grid[i][j];
}
}
for (pair<int, int> p : mushrooms) {
r1 = (p.f + d >= r ? r : p.f + d);
c1 = (p.s + d >= c ? c : p.s + d);
r2 = (p.f - d - 1 >= 0 ? p.f - d - 1 : 0);
c2 = (p.s - d - 1 >= 0 ? p.s - d - 1 : 0);
spr = pref[r1][c1] - pref[r1][c2] - pref[r2][c1] + pref[r2][c2];
if (spr >= k) ans++;
}
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
584 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2132 KB |
Output is correct |
2 |
Correct |
5 ms |
2132 KB |
Output is correct |
3 |
Correct |
5 ms |
2516 KB |
Output is correct |
4 |
Correct |
5 ms |
2124 KB |
Output is correct |
5 |
Correct |
5 ms |
2260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
28572 KB |
Output is correct |
2 |
Correct |
28 ms |
31308 KB |
Output is correct |
3 |
Correct |
27 ms |
31396 KB |
Output is correct |
4 |
Correct |
26 ms |
28836 KB |
Output is correct |
5 |
Correct |
26 ms |
31400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
320 KB |
Output is correct |
13 |
Correct |
1 ms |
584 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
452 KB |
Output is correct |
16 |
Correct |
4 ms |
2132 KB |
Output is correct |
17 |
Correct |
5 ms |
2132 KB |
Output is correct |
18 |
Correct |
5 ms |
2516 KB |
Output is correct |
19 |
Correct |
5 ms |
2124 KB |
Output is correct |
20 |
Correct |
5 ms |
2260 KB |
Output is correct |
21 |
Correct |
28 ms |
28572 KB |
Output is correct |
22 |
Correct |
28 ms |
31308 KB |
Output is correct |
23 |
Correct |
27 ms |
31396 KB |
Output is correct |
24 |
Correct |
26 ms |
28836 KB |
Output is correct |
25 |
Correct |
26 ms |
31400 KB |
Output is correct |
26 |
Correct |
16 ms |
8276 KB |
Output is correct |
27 |
Correct |
15 ms |
6852 KB |
Output is correct |
28 |
Correct |
16 ms |
6220 KB |
Output is correct |
29 |
Correct |
15 ms |
6244 KB |
Output is correct |
30 |
Correct |
18 ms |
8688 KB |
Output is correct |