#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int r,c,d,k;
cin>>r>>c>>d>>k;
vector<vector<int>> arr(r+1, vector<int>(c+1, 0));
vector<vector<int>> dp(r+1, vector<int>(c+1, 0));
for(int i=1;i<=r;i++) {
for(int j=1;j<=c;j++) {
char s;
cin>>s;
arr[i][j] = s;
dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1];
if (s=='S') dp[i][j]++;
}
}
int ans = 0;
for(int i=1;i<=r;i++) {
for(int j=1;j<=c;j++) {
if (arr[i][j] != 'M') continue;
int u = max(i-d,1);
int v = max(j-d,1);
int w = min(i+d,r);
int x = min(j+d,c);
int count = dp[w][x]-dp[u-1][x]-dp[w][v-1]+dp[u-1][v-1];
if (count>= k) ans++;
}
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2004 KB |
Output is correct |
2 |
Correct |
6 ms |
2068 KB |
Output is correct |
3 |
Correct |
7 ms |
2516 KB |
Output is correct |
4 |
Correct |
7 ms |
2132 KB |
Output is correct |
5 |
Correct |
8 ms |
2260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
10592 KB |
Output is correct |
2 |
Correct |
21 ms |
10496 KB |
Output is correct |
3 |
Correct |
21 ms |
10488 KB |
Output is correct |
4 |
Correct |
22 ms |
10592 KB |
Output is correct |
5 |
Correct |
24 ms |
10672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
320 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
6 ms |
2004 KB |
Output is correct |
17 |
Correct |
6 ms |
2068 KB |
Output is correct |
18 |
Correct |
7 ms |
2516 KB |
Output is correct |
19 |
Correct |
7 ms |
2132 KB |
Output is correct |
20 |
Correct |
8 ms |
2260 KB |
Output is correct |
21 |
Correct |
23 ms |
10592 KB |
Output is correct |
22 |
Correct |
21 ms |
10496 KB |
Output is correct |
23 |
Correct |
21 ms |
10488 KB |
Output is correct |
24 |
Correct |
22 ms |
10592 KB |
Output is correct |
25 |
Correct |
24 ms |
10672 KB |
Output is correct |
26 |
Correct |
20 ms |
6356 KB |
Output is correct |
27 |
Correct |
14 ms |
4692 KB |
Output is correct |
28 |
Correct |
15 ms |
4696 KB |
Output is correct |
29 |
Correct |
14 ms |
4820 KB |
Output is correct |
30 |
Correct |
17 ms |
6004 KB |
Output is correct |