#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int n, m, d, s; cin >> n >> m >> d >> s;
string grid[n + 5];
for ( int i = 0; i < n; i++) cin >> grid[i];
int ans[n + 5][m + 5];
memset ( ans, 0, sizeof(ans));
for ( int i = 0; i < n; i++){
for ( int j = 0; j < m; j++){
if ( grid[i][j] == 'S' ){
int x1 = max ( 0ll, i - d), x2 = min ( n, i + d);
int y1 = max ( 0ll, j - d ), y2 = min ( m, j + d);
ans[x1][y1]++;
if ( y2 + 1 < m ) ans[x1][y2 + 1]--;
if ( x2 + 1 < n ) ans[x2 + 1][y1]--;
if ( x2 + 1 < n && y2 + 1 < m ) ans[x2 + 1][y2 + 1]++;
}
}
}
int cnt = 0;
for ( int i = 0; i < n; i++){
for ( int j = 0; j < m; j++){
if ( i - 1 >= 0 ){
ans[i][j] += ans[i - 1][j];
}
if ( j - 1 >= 0 ){
ans[i][j] += ans[i][j - 1];
}
if ( i - 1 >= 0 && j - 1 >= 0 ){
ans[i][j] -= ans[i - 1][j - 1];
}
}
}
for ( int i = 0; i < n; i++){
for ( int j = 0; j < m; j++){
if ( grid[i][j] == 'M' ){
if ( ans[i][j] >= s ) cnt++;
}
}
}
cout << cnt << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2140 KB |
Output is correct |
2 |
Correct |
2 ms |
2276 KB |
Output is correct |
3 |
Correct |
2 ms |
2652 KB |
Output is correct |
4 |
Correct |
2 ms |
2140 KB |
Output is correct |
5 |
Correct |
2 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
24556 KB |
Output is correct |
2 |
Correct |
15 ms |
24560 KB |
Output is correct |
3 |
Correct |
13 ms |
24408 KB |
Output is correct |
4 |
Correct |
17 ms |
24480 KB |
Output is correct |
5 |
Correct |
15 ms |
24304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
2140 KB |
Output is correct |
17 |
Correct |
2 ms |
2276 KB |
Output is correct |
18 |
Correct |
2 ms |
2652 KB |
Output is correct |
19 |
Correct |
2 ms |
2140 KB |
Output is correct |
20 |
Correct |
2 ms |
2392 KB |
Output is correct |
21 |
Correct |
16 ms |
24556 KB |
Output is correct |
22 |
Correct |
15 ms |
24560 KB |
Output is correct |
23 |
Correct |
13 ms |
24408 KB |
Output is correct |
24 |
Correct |
17 ms |
24480 KB |
Output is correct |
25 |
Correct |
15 ms |
24304 KB |
Output is correct |
26 |
Correct |
11 ms |
6748 KB |
Output is correct |
27 |
Correct |
7 ms |
4956 KB |
Output is correct |
28 |
Correct |
9 ms |
5464 KB |
Output is correct |
29 |
Correct |
5 ms |
5212 KB |
Output is correct |
30 |
Correct |
6 ms |
5980 KB |
Output is correct |