#include<bits/stdc++.h>
using namespace std;
struct Fenwick{
vector<int>BIT;
int sz;
void Update(int pos, int val){
while(pos <= sz){
BIT[pos] += val;
pos += (pos & -pos);
}
}
int Query(int pos){
int sum = 0;
while(pos > 0){
sum += BIT[pos];
pos -= (pos & -pos);
}
return sum;
}
};
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, d, k;
cin >> n >> m >> d >> k;
vector<vector<char>>grid(n + 1, vector<char>(m + 1));
Fenwick tree[m + 1];
for(int i = 0;i <= m;++i){
tree[i].BIT.resize(n + 1);
tree[i].sz = n;
}
for(int i = 1;i <= n;++i){
for(int j = 1;j <= m;++j){
cin >> grid[i][j];
if(grid[i][j] == 'S'){
int x = max(i - d, 1);
int y = max(j - d, 1);
int x_end = min(i + d, n);
int y_end = min(j + d, m);
tree[y].Update(x, 1);
if(x_end + 1 <= n)tree[y].Update(x_end + 1, -1);
if(y_end + 1 <= m){
tree[y_end + 1].Update(x, -1);
if(x_end + 1 <= n)tree[y_end + 1].Update(x_end + 1, 1);
}
}
}
}
int res = 0;
for(int i = 1;i <= n;++i){
int sum = 0;
for(int j = 1;j <= m;++j){
sum += tree[j].Query(i);
if(grid[i][j] == 'M' && sum >= k){
res++;
}
}
}
cout << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1624 KB |
Output is correct |
2 |
Correct |
4 ms |
1488 KB |
Output is correct |
3 |
Correct |
5 ms |
1884 KB |
Output is correct |
4 |
Correct |
4 ms |
1628 KB |
Output is correct |
5 |
Correct |
6 ms |
2096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
33128 KB |
Output is correct |
2 |
Correct |
35 ms |
33124 KB |
Output is correct |
3 |
Correct |
37 ms |
33060 KB |
Output is correct |
4 |
Correct |
39 ms |
33128 KB |
Output is correct |
5 |
Correct |
38 ms |
33136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
1624 KB |
Output is correct |
17 |
Correct |
4 ms |
1488 KB |
Output is correct |
18 |
Correct |
5 ms |
1884 KB |
Output is correct |
19 |
Correct |
4 ms |
1628 KB |
Output is correct |
20 |
Correct |
6 ms |
2096 KB |
Output is correct |
21 |
Correct |
37 ms |
33128 KB |
Output is correct |
22 |
Correct |
35 ms |
33124 KB |
Output is correct |
23 |
Correct |
37 ms |
33060 KB |
Output is correct |
24 |
Correct |
39 ms |
33128 KB |
Output is correct |
25 |
Correct |
38 ms |
33136 KB |
Output is correct |
26 |
Correct |
13 ms |
4236 KB |
Output is correct |
27 |
Correct |
11 ms |
3420 KB |
Output is correct |
28 |
Correct |
11 ms |
4140 KB |
Output is correct |
29 |
Correct |
10 ms |
3852 KB |
Output is correct |
30 |
Correct |
11 ms |
3932 KB |
Output is correct |