#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 11;
char a[MAXN];
int dp[MAXN];
int r, c, d, k;
int id(int i, int j){
return i * c + j;
}
int main(){
cin >> r >> c >> d >> k;
for(int i = 0; i < r; i++){
for(int j = 0; j < c; j++){
cin >> a[i * c + j];
}
}
for(int i = 0; i < r; i++){
for(int j = 0; j < c; j++){
if(a[i * c + j] == 'S'){
int r1 = max(0, i - d), r2 = min(r - 1, i + d);
int c1 = max(0, j - d), c2 = min(c - 1, j + d);
dp[r1 * c + c1]++;
if(r2 != r - 1) dp[(r2 + 1) * c + c1]--;
if(c2 != c - 1) dp[r1 * c + (c2 + 1)]--;
if(r2 != r - 1 && c2 != c - 1) dp[(r2 + 1) * c + (c2 + 1)]++;
}
}
}
int ans = 0;
for(int i = 0; i < r; i++){
for(int j = 0; j < c; j++){
if(i > 0 && j > 0) dp[i * c + j] -= dp[(i - 1) * c + j - 1];
if(i > 0) dp[i * c + j] += dp[(i - 1) * c + j];
if(j > 0) dp[i * c + j] += dp[i * c + j - 1];
if(a[i * c + j] == 'M' && dp[i * c + j] >= k) ans++;
}
}
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2904 KB |
Output is correct |
2 |
Correct |
8 ms |
2700 KB |
Output is correct |
3 |
Correct |
9 ms |
2916 KB |
Output is correct |
4 |
Correct |
8 ms |
2648 KB |
Output is correct |
5 |
Correct |
8 ms |
2648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
3160 KB |
Output is correct |
2 |
Correct |
19 ms |
3376 KB |
Output is correct |
3 |
Correct |
22 ms |
3164 KB |
Output is correct |
4 |
Correct |
19 ms |
3152 KB |
Output is correct |
5 |
Correct |
18 ms |
3160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
7 ms |
2904 KB |
Output is correct |
17 |
Correct |
8 ms |
2700 KB |
Output is correct |
18 |
Correct |
9 ms |
2916 KB |
Output is correct |
19 |
Correct |
8 ms |
2648 KB |
Output is correct |
20 |
Correct |
8 ms |
2648 KB |
Output is correct |
21 |
Correct |
19 ms |
3160 KB |
Output is correct |
22 |
Correct |
19 ms |
3376 KB |
Output is correct |
23 |
Correct |
22 ms |
3164 KB |
Output is correct |
24 |
Correct |
19 ms |
3152 KB |
Output is correct |
25 |
Correct |
18 ms |
3160 KB |
Output is correct |
26 |
Correct |
20 ms |
3152 KB |
Output is correct |
27 |
Correct |
19 ms |
3160 KB |
Output is correct |
28 |
Correct |
19 ms |
3152 KB |
Output is correct |
29 |
Correct |
19 ms |
3160 KB |
Output is correct |
30 |
Correct |
19 ms |
3312 KB |
Output is correct |