#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int n,m,d,k;
vector<int> A[500005], S[500005];
char tmp[500005];
vector<pii> mush;
int cnt(int x1,int y1,int x2,int y2) {
x2 = min(x2, n);
y2 = min(y2, m);
x1--; y1--;
x1 = max(0, x1);
y1 = max(0, y1);
return S[x2][y2] - S[x1][y2] - S[x2][y1] + S[x1][y1];
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n>>m>>d>>k;
for(int j=1;j<=n;j++) {
cin>>tmp;
int len = strlen(tmp);
A[j].push_back(0);
for(int i=0;i<len;i++) {
A[j].push_back(0);
if(tmp[i] == 'S') A[j].back() = 1;
if(tmp[i] == 'M') {
mush.push_back(pii(j,i+1));
}
}
}
for(int j=0;j<=m;j++) S[0].push_back(0);
for(int i=1;i<=n;i++) {
S[i].push_back(0);
for(int j=1;j<=m;j++) {
S[i].push_back(0);
S[i][j] = A[i][j] + S[i-1][j] + S[i][j-1] - S[i-1][j-1];
}
}
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
//cout<<S[i][j]<<' ';
}
// cout<<'\n';
}
//cout<<'\n';
int ans = 0;
for(pii p : mush) {
//cout<<p.first<<' '<<p.second<<' '<<cnt(p.first - d, p.second - d, p.first + d, p.second + d)<<'\n';
ans += (cnt(p.first - d, p.second - d, p.first + d, p.second + d) >= k);
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Output is correct |
2 |
Correct |
22 ms |
23928 KB |
Output is correct |
3 |
Correct |
23 ms |
23928 KB |
Output is correct |
4 |
Correct |
22 ms |
23928 KB |
Output is correct |
5 |
Correct |
22 ms |
23932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Output is correct |
2 |
Correct |
22 ms |
23928 KB |
Output is correct |
3 |
Correct |
23 ms |
23928 KB |
Output is correct |
4 |
Correct |
22 ms |
23928 KB |
Output is correct |
5 |
Correct |
22 ms |
23932 KB |
Output is correct |
6 |
Correct |
22 ms |
23800 KB |
Output is correct |
7 |
Correct |
22 ms |
23800 KB |
Output is correct |
8 |
Correct |
23 ms |
23928 KB |
Output is correct |
9 |
Correct |
23 ms |
23928 KB |
Output is correct |
10 |
Correct |
22 ms |
23800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23928 KB |
Output is correct |
2 |
Correct |
22 ms |
23932 KB |
Output is correct |
3 |
Correct |
22 ms |
24056 KB |
Output is correct |
4 |
Correct |
22 ms |
23800 KB |
Output is correct |
5 |
Correct |
24 ms |
23928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
25620 KB |
Output is correct |
2 |
Correct |
28 ms |
25720 KB |
Output is correct |
3 |
Correct |
29 ms |
25852 KB |
Output is correct |
4 |
Correct |
29 ms |
25464 KB |
Output is correct |
5 |
Correct |
30 ms |
25848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
32568 KB |
Output is correct |
2 |
Correct |
48 ms |
35928 KB |
Output is correct |
3 |
Correct |
47 ms |
35016 KB |
Output is correct |
4 |
Correct |
45 ms |
32896 KB |
Output is correct |
5 |
Correct |
49 ms |
35536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Output is correct |
2 |
Correct |
22 ms |
23928 KB |
Output is correct |
3 |
Correct |
23 ms |
23928 KB |
Output is correct |
4 |
Correct |
22 ms |
23928 KB |
Output is correct |
5 |
Correct |
22 ms |
23932 KB |
Output is correct |
6 |
Correct |
22 ms |
23800 KB |
Output is correct |
7 |
Correct |
22 ms |
23800 KB |
Output is correct |
8 |
Correct |
23 ms |
23928 KB |
Output is correct |
9 |
Correct |
23 ms |
23928 KB |
Output is correct |
10 |
Correct |
22 ms |
23800 KB |
Output is correct |
11 |
Correct |
23 ms |
23928 KB |
Output is correct |
12 |
Correct |
22 ms |
23932 KB |
Output is correct |
13 |
Correct |
22 ms |
24056 KB |
Output is correct |
14 |
Correct |
22 ms |
23800 KB |
Output is correct |
15 |
Correct |
24 ms |
23928 KB |
Output is correct |
16 |
Correct |
29 ms |
25620 KB |
Output is correct |
17 |
Correct |
28 ms |
25720 KB |
Output is correct |
18 |
Correct |
29 ms |
25852 KB |
Output is correct |
19 |
Correct |
29 ms |
25464 KB |
Output is correct |
20 |
Correct |
30 ms |
25848 KB |
Output is correct |
21 |
Correct |
45 ms |
32568 KB |
Output is correct |
22 |
Correct |
48 ms |
35928 KB |
Output is correct |
23 |
Correct |
47 ms |
35016 KB |
Output is correct |
24 |
Correct |
45 ms |
32896 KB |
Output is correct |
25 |
Correct |
49 ms |
35536 KB |
Output is correct |
26 |
Correct |
52 ms |
31592 KB |
Output is correct |
27 |
Correct |
39 ms |
31324 KB |
Output is correct |
28 |
Correct |
37 ms |
28908 KB |
Output is correct |
29 |
Correct |
36 ms |
28880 KB |
Output is correct |
30 |
Correct |
48 ms |
29508 KB |
Output is correct |