#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(0);
#define ll int
#define pb push_back
#define tc long long int t; cin >> t; while(t--)
#define vpll vector<pair<ll,ll>>
#define MOD 1000000007
int main(){
boost;
ll i;
ll r,c,d,k;
cin >> r >> c >> d >> k;
char a[r+1][c+1];
ll diff[r+1][c+1];
ll pre[r+1][c+1];
ll j;
for(i = 1; i <= r; i++){
for(j = 1; j <= c; j++){
cin >> a[i][j];
if(a[i][j] == 'S'){
diff[i][j] = 1;
}
else{
diff[i][j] = 0;
}
}
}
for(i= 0 ; i<= r; i++){
for(j = 0; j <= c; j++){
pre[i][j] = 0;
}
}
/*for(i = 0; i <= r; i++){
diff[i][0] = 0;
}
for(j = 0; j <= c; j++){
diff[0][j] = 0;
}
pre[1][1] = diff[1][1];
for(i = 1; i <= r; i++){
pre[i][0] = pre[i-1][0] + diff[i][0];
}
for(i = 1; i < c; i++){
pre[0][i] = pre[0][i-1] + diff[0][i];
}*/
for(i = 1; i <= r; i++){
for(j = 1; j <= c; j++){
pre[i][j] = (diff[i][j] + pre[i-1][j] + pre[i][j-1]) - pre[i-1][j-1];
//cout << "1" <<endl;
}
}
ll u,v,x,y, ans = 0;;
/*for(i = 0; i < r; i++){
for(j = 0; j < c; j++){
cout << pre[i][j] << " ";
}
cout << endl;
}*/
for(i = 1; i <= r; i++){
for(j = 1; j <= c; j++){
if(a[i][j] == 'M'){
u = max(1,i-d);
v = max(1,j-d);
x = min(r, i+d);
y = min(c, j+d);
ll temp = pre[x][y] - pre[u-1][y] - pre[x][v-1] + pre[u-1][v-1];
if(temp >= k){
ans++;
//cout << "i " << i << " j " << j <<endl;
}
}
//cout << "1" << endl;
}
}
cout << ans <<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
232 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 |
320 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
232 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 |
320 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
320 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2132 KB |
Output is correct |
2 |
Correct |
8 ms |
2260 KB |
Output is correct |
3 |
Correct |
7 ms |
2656 KB |
Output is correct |
4 |
Correct |
6 ms |
2240 KB |
Output is correct |
5 |
Correct |
8 ms |
2388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
9484 KB |
Output is correct |
2 |
Correct |
17 ms |
9492 KB |
Output is correct |
3 |
Correct |
15 ms |
9556 KB |
Output is correct |
4 |
Correct |
17 ms |
9616 KB |
Output is correct |
5 |
Correct |
18 ms |
9616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
232 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 |
320 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
316 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
320 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
5 ms |
2132 KB |
Output is correct |
17 |
Correct |
8 ms |
2260 KB |
Output is correct |
18 |
Correct |
7 ms |
2656 KB |
Output is correct |
19 |
Correct |
6 ms |
2240 KB |
Output is correct |
20 |
Correct |
8 ms |
2388 KB |
Output is correct |
21 |
Correct |
22 ms |
9484 KB |
Output is correct |
22 |
Correct |
17 ms |
9492 KB |
Output is correct |
23 |
Correct |
15 ms |
9556 KB |
Output is correct |
24 |
Correct |
17 ms |
9616 KB |
Output is correct |
25 |
Correct |
18 ms |
9616 KB |
Output is correct |
26 |
Correct |
14 ms |
5232 KB |
Output is correct |
27 |
Correct |
14 ms |
5196 KB |
Output is correct |
28 |
Correct |
16 ms |
5256 KB |
Output is correct |
29 |
Correct |
17 ms |
5148 KB |
Output is correct |
30 |
Correct |
14 ms |
5244 KB |
Output is correct |