#include<bits/stdc++.h>
using namespace std;
char c[501][501];
bool check[501][501];
int diff[501][501];
int r,w,d,k;
int main(){
cin>>r>>w>>d>>k;
for(int i=0;i<r;i++){
for(int j=0;j<w;j++){
diff[i][j]=0;
check[i][j]=false;
}
}
for(int i=0;i<r;i++){
for(int j=0;j<w;j++){
cin>>c[i][j];
if(c[i][j]=='M')check[i][j]=true;
else if(c[i][j]=='S'){
int up=max(0,i-d);
int down=min(r-1,i+d);
int left=max(0,j-d);
int right=min(w-1,j+d);
diff[up][left]++;
diff[up][right+1]--;
diff[down+1][left]--;
diff[down+1][right+1]++;
}
}
}
for(int i=1;i<w;i++) diff[0][i]+=diff[0][i-1];
for(int i=1;i<r;i++) diff[i][0]+=diff[i-1][0];
for(int i=1;i<=r;i++){
for(int j=1;j<=w;j++)
diff[i][j]+=diff[i-1][j]+diff[i][j-1]-diff[i-1][j-1];
}
// for(int i=0;i<r;i++){
// for(int j=0;j<w;j++)
// cout<<diff[i][j]<<" ";
// cout<<endl;
// }
int ans=0;
for(int i=0;i<r;i++)
for(int j=0;j<w;j++)
if(check[i][j]==true && diff[i][j]>=k)
ans++;
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
3 ms |
632 KB |
Output is correct |
3 |
Correct |
11 ms |
632 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
3 ms |
632 KB |
Output is correct |
3 |
Correct |
11 ms |
632 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
632 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
4 ms |
632 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
632 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
1788 KB |
Output is correct |
2 |
Correct |
24 ms |
1864 KB |
Output is correct |
3 |
Correct |
28 ms |
2040 KB |
Output is correct |
4 |
Correct |
25 ms |
1784 KB |
Output is correct |
5 |
Correct |
25 ms |
2040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
3448 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
3 ms |
632 KB |
Output is correct |
3 |
Correct |
11 ms |
632 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
632 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
4 ms |
632 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
3 ms |
504 KB |
Output is correct |
13 |
Correct |
3 ms |
632 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
3 ms |
632 KB |
Output is correct |
16 |
Correct |
24 ms |
1788 KB |
Output is correct |
17 |
Correct |
24 ms |
1864 KB |
Output is correct |
18 |
Correct |
28 ms |
2040 KB |
Output is correct |
19 |
Correct |
25 ms |
1784 KB |
Output is correct |
20 |
Correct |
25 ms |
2040 KB |
Output is correct |
21 |
Runtime error |
6 ms |
3448 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
22 |
Halted |
0 ms |
0 KB |
- |