#include <bits/stdc++.h>
using namespace std;
const int N = 5e5+7;
int numRow, numCol, maxDist, minNum;
vector<int> a[N];
string s[N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
#ifdef NHPHUCQT
freopen("demo.inp", "r", stdin);
freopen("demo.out", "w", stdout);
#endif // NHPHUCQT
cin >> numRow >> numCol >> maxDist >> minNum;
for (int i = 0; i <= numRow+3; ++i) {
a[i].resize(numCol+3, 0);
}
for (int i = 1; i <= numRow; ++i) {
cin >> s[i];
s[i] = '0' + s[i];
}
for (int i = 1; i <= numRow; ++i)
for (int j = 1; j <= numCol; ++j) {
// s[i][j]
if (s[i][j] == 'S') {
int x = max(1, i - maxDist);
int y = max(1, j - maxDist);
int u = min(numRow, i + maxDist);
int v = min(numCol, j + maxDist);
a[x][y]++;
a[x][v+1]--;
a[u+1][y]--;
a[u+1][v+1]++;
}
}
for (int i = 1; i <= numRow; ++i)
for (int j = 1; j <= numCol; ++j) {
a[i][j] += a[i][j-1];
}
for (int j = 1; j <= numCol; ++j)
for (int i = 1; i <= numRow; ++i) {
a[i][j] += a[i-1][j];
}
int res = 0;
for (int i = 1; i <= numRow; ++i)
for (int j = 1; j <= numCol; ++j) {
if (s[i][j] == 'M') {
res += a[i][j] >= minNum;
}
}
cout << res;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
27596 KB |
Output is correct |
2 |
Correct |
16 ms |
27708 KB |
Output is correct |
3 |
Correct |
16 ms |
27724 KB |
Output is correct |
4 |
Correct |
15 ms |
27596 KB |
Output is correct |
5 |
Correct |
13 ms |
27724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
27596 KB |
Output is correct |
2 |
Correct |
16 ms |
27708 KB |
Output is correct |
3 |
Correct |
16 ms |
27724 KB |
Output is correct |
4 |
Correct |
15 ms |
27596 KB |
Output is correct |
5 |
Correct |
13 ms |
27724 KB |
Output is correct |
6 |
Correct |
13 ms |
27648 KB |
Output is correct |
7 |
Correct |
13 ms |
27596 KB |
Output is correct |
8 |
Correct |
14 ms |
27668 KB |
Output is correct |
9 |
Correct |
15 ms |
27724 KB |
Output is correct |
10 |
Correct |
12 ms |
27708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
27608 KB |
Output is correct |
2 |
Correct |
14 ms |
27720 KB |
Output is correct |
3 |
Correct |
17 ms |
27768 KB |
Output is correct |
4 |
Correct |
14 ms |
27596 KB |
Output is correct |
5 |
Correct |
18 ms |
27684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
28872 KB |
Output is correct |
2 |
Correct |
15 ms |
28876 KB |
Output is correct |
3 |
Correct |
15 ms |
29132 KB |
Output is correct |
4 |
Correct |
17 ms |
28960 KB |
Output is correct |
5 |
Correct |
17 ms |
29056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
39008 KB |
Output is correct |
2 |
Correct |
30 ms |
38988 KB |
Output is correct |
3 |
Correct |
29 ms |
39008 KB |
Output is correct |
4 |
Correct |
27 ms |
39020 KB |
Output is correct |
5 |
Correct |
25 ms |
39024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
27596 KB |
Output is correct |
2 |
Correct |
16 ms |
27708 KB |
Output is correct |
3 |
Correct |
16 ms |
27724 KB |
Output is correct |
4 |
Correct |
15 ms |
27596 KB |
Output is correct |
5 |
Correct |
13 ms |
27724 KB |
Output is correct |
6 |
Correct |
13 ms |
27648 KB |
Output is correct |
7 |
Correct |
13 ms |
27596 KB |
Output is correct |
8 |
Correct |
14 ms |
27668 KB |
Output is correct |
9 |
Correct |
15 ms |
27724 KB |
Output is correct |
10 |
Correct |
12 ms |
27708 KB |
Output is correct |
11 |
Correct |
13 ms |
27608 KB |
Output is correct |
12 |
Correct |
14 ms |
27720 KB |
Output is correct |
13 |
Correct |
17 ms |
27768 KB |
Output is correct |
14 |
Correct |
14 ms |
27596 KB |
Output is correct |
15 |
Correct |
18 ms |
27684 KB |
Output is correct |
16 |
Correct |
16 ms |
28872 KB |
Output is correct |
17 |
Correct |
15 ms |
28876 KB |
Output is correct |
18 |
Correct |
15 ms |
29132 KB |
Output is correct |
19 |
Correct |
17 ms |
28960 KB |
Output is correct |
20 |
Correct |
17 ms |
29056 KB |
Output is correct |
21 |
Correct |
26 ms |
39008 KB |
Output is correct |
22 |
Correct |
30 ms |
38988 KB |
Output is correct |
23 |
Correct |
29 ms |
39008 KB |
Output is correct |
24 |
Correct |
27 ms |
39020 KB |
Output is correct |
25 |
Correct |
25 ms |
39024 KB |
Output is correct |
26 |
Correct |
26 ms |
32048 KB |
Output is correct |
27 |
Correct |
20 ms |
30652 KB |
Output is correct |
28 |
Correct |
21 ms |
30888 KB |
Output is correct |
29 |
Correct |
23 ms |
30832 KB |
Output is correct |
30 |
Correct |
26 ms |
31208 KB |
Output is correct |