#include<bits/stdc++.h>
using namespace std;
int n, m, d, k, ans=0;
string S[500010];
vector<vector<int>> s;
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//freopen("collect.inp", "r", stdin);
//freopen("collect.out", "w", stdout);
cin>>n>>m>>d>>k;
for(int i=0;i<n;i++){
cin>>S[i];
}
for(int i=0;i<=n;i++){
vector<int> row;
for(int j=0;j<=m;j++)row.push_back(0);
s.push_back(row);
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
s[i+1][j+1]=s[i+1][j]+s[i][j+1]-s[i][j];
if(S[i][j]=='S')s[i+1][j+1]++;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(S[i][j]=='M'){
int o1=i+d, o2=i-d, o3=j-d, o4=j+d;
int l=max(0, o3);
int r=min(m-1, o4);
int d=max(0, o2);
int u=min(o1, n-1);
if(s[u+1][r+1]-s[u+1][l]-s[d][r+1]+s[d][l]>=k)ans++;
}
}
}
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
15964 KB |
Output is correct |
2 |
Correct |
7 ms |
16136 KB |
Output is correct |
3 |
Correct |
6 ms |
16156 KB |
Output is correct |
4 |
Correct |
7 ms |
15964 KB |
Output is correct |
5 |
Correct |
6 ms |
16084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
15964 KB |
Output is correct |
2 |
Correct |
7 ms |
16136 KB |
Output is correct |
3 |
Correct |
6 ms |
16156 KB |
Output is correct |
4 |
Correct |
7 ms |
15964 KB |
Output is correct |
5 |
Correct |
6 ms |
16084 KB |
Output is correct |
6 |
Correct |
6 ms |
15964 KB |
Output is correct |
7 |
Correct |
6 ms |
16116 KB |
Output is correct |
8 |
Correct |
7 ms |
16044 KB |
Output is correct |
9 |
Correct |
6 ms |
15964 KB |
Output is correct |
10 |
Correct |
7 ms |
15964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
15960 KB |
Output is correct |
2 |
Correct |
7 ms |
15964 KB |
Output is correct |
3 |
Correct |
9 ms |
15964 KB |
Output is correct |
4 |
Correct |
6 ms |
15964 KB |
Output is correct |
5 |
Correct |
7 ms |
15964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
17148 KB |
Output is correct |
2 |
Correct |
9 ms |
17244 KB |
Output is correct |
3 |
Correct |
9 ms |
17408 KB |
Output is correct |
4 |
Correct |
8 ms |
17164 KB |
Output is correct |
5 |
Correct |
9 ms |
17240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23076 KB |
Output is correct |
2 |
Correct |
20 ms |
22848 KB |
Output is correct |
3 |
Correct |
20 ms |
22848 KB |
Output is correct |
4 |
Correct |
16 ms |
23084 KB |
Output is correct |
5 |
Correct |
15 ms |
22880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
15964 KB |
Output is correct |
2 |
Correct |
7 ms |
16136 KB |
Output is correct |
3 |
Correct |
6 ms |
16156 KB |
Output is correct |
4 |
Correct |
7 ms |
15964 KB |
Output is correct |
5 |
Correct |
6 ms |
16084 KB |
Output is correct |
6 |
Correct |
6 ms |
15964 KB |
Output is correct |
7 |
Correct |
6 ms |
16116 KB |
Output is correct |
8 |
Correct |
7 ms |
16044 KB |
Output is correct |
9 |
Correct |
6 ms |
15964 KB |
Output is correct |
10 |
Correct |
7 ms |
15964 KB |
Output is correct |
11 |
Correct |
7 ms |
15960 KB |
Output is correct |
12 |
Correct |
7 ms |
15964 KB |
Output is correct |
13 |
Correct |
9 ms |
15964 KB |
Output is correct |
14 |
Correct |
6 ms |
15964 KB |
Output is correct |
15 |
Correct |
7 ms |
15964 KB |
Output is correct |
16 |
Correct |
9 ms |
17148 KB |
Output is correct |
17 |
Correct |
9 ms |
17244 KB |
Output is correct |
18 |
Correct |
9 ms |
17408 KB |
Output is correct |
19 |
Correct |
8 ms |
17164 KB |
Output is correct |
20 |
Correct |
9 ms |
17240 KB |
Output is correct |
21 |
Correct |
16 ms |
23076 KB |
Output is correct |
22 |
Correct |
20 ms |
22848 KB |
Output is correct |
23 |
Correct |
20 ms |
22848 KB |
Output is correct |
24 |
Correct |
16 ms |
23084 KB |
Output is correct |
25 |
Correct |
15 ms |
22880 KB |
Output is correct |
26 |
Correct |
25 ms |
20500 KB |
Output is correct |
27 |
Correct |
11 ms |
18940 KB |
Output is correct |
28 |
Correct |
12 ms |
19288 KB |
Output is correct |
29 |
Correct |
13 ms |
19032 KB |
Output is correct |
30 |
Correct |
15 ms |
19864 KB |
Output is correct |