#include<bits/stdc++.h>
using namespace std;
struct SegmentTree{
vector<int>sTree;
vector<int>lazy;
void Propagate(int node, int l, int r){
if(!lazy[node])return;
sTree[node] += lazy[node];
if(l != r){
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
lazy[node] = 0;
}
void R_Update(int node, int l, int r, int ql, int qr, int val){
Propagate(node, l, r);
if(ql <= l && r <= qr){
lazy[node] += val;
Propagate(node, l, r);
return;
}
if(ql > r || l > qr)return;
int mid = (l + r) >> 1;
R_Update(node * 2, l, mid, ql, qr, val);
R_Update(node * 2 + 1, mid + 1, r, ql, qr, val);
sTree[node] = sTree[node * 2] + sTree[node * 2 + 1];
}
int Query(int node, int l, int r, int pos){
Propagate(node, l, r);
if(l == r)return sTree[node];
int mid = (l + r) >> 1;
if(pos <= mid){
return Query(node * 2, l, mid, pos);
}
return Query(node * 2 + 1, mid + 1, r, pos);
}
};
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));
SegmentTree tree[m + 1];
for(int i = 0;i <= m;++i){
tree[i].sTree.resize(4 * n);
tree[i].lazy.resize(4 * 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].R_Update(1, 1, n, x, x_end, 1);
if(y_end + 1 <= m)tree[y_end + 1].R_Update(1, 1, n, x, x_end, -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(1, 1, n, i);
if(grid[i][j] == 'M' && sum >= k){
res++;
}
}
}
cout << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
6748 KB |
Output is correct |
2 |
Correct |
12 ms |
7004 KB |
Output is correct |
3 |
Correct |
14 ms |
8600 KB |
Output is correct |
4 |
Correct |
13 ms |
7004 KB |
Output is correct |
5 |
Correct |
13 ms |
7516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
56176 KB |
Output is correct |
2 |
Correct |
62 ms |
56164 KB |
Output is correct |
3 |
Correct |
67 ms |
56164 KB |
Output is correct |
4 |
Correct |
68 ms |
56180 KB |
Output is correct |
5 |
Correct |
67 ms |
56176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
10 ms |
6748 KB |
Output is correct |
17 |
Correct |
12 ms |
7004 KB |
Output is correct |
18 |
Correct |
14 ms |
8600 KB |
Output is correct |
19 |
Correct |
13 ms |
7004 KB |
Output is correct |
20 |
Correct |
13 ms |
7516 KB |
Output is correct |
21 |
Correct |
64 ms |
56176 KB |
Output is correct |
22 |
Correct |
62 ms |
56164 KB |
Output is correct |
23 |
Correct |
67 ms |
56164 KB |
Output is correct |
24 |
Correct |
68 ms |
56180 KB |
Output is correct |
25 |
Correct |
67 ms |
56176 KB |
Output is correct |
26 |
Correct |
35 ms |
17496 KB |
Output is correct |
27 |
Correct |
45 ms |
17244 KB |
Output is correct |
28 |
Correct |
31 ms |
17752 KB |
Output is correct |
29 |
Correct |
29 ms |
17716 KB |
Output is correct |
30 |
Correct |
37 ms |
17756 KB |
Output is correct |