This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
int r,c,d,k;
cin>>r>>c>>d>>k;
vector<vector<char>> g(r+1,vector<char>(c+2));
vector<vector<int>> prefix(r+2,vector<int>(c+2));
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
cin>>g[i][j];
if(g[i][j]=='S'){
int one=1;
int start_x=max(one,i-d),start_y=max(one,j-d);
int end_x=min(r+1,i+d),end_y=min(c+1,j+d);
//cout<<start_x<<" "<<start_y<<" "<<end_x<<" "<<end_y<<endl;
prefix[start_x][start_y]++;
prefix[end_x][end_y]++;
prefix[start_x][end_y]--;
prefix[end_x][start_y]--;
}
}
}
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
prefix[i][j]=prefix[i][j]
+prefix[i-1][j]
+prefix[i][j-1]
-prefix[i-1][j-1];
}
}
int ans=0;
for(int i=0;i<=r;i++){
for(int j=0;j<=c;j++){
if(prefix[i][j]>=k&&g[i][j]=='M')
{
ans++;
}
//cout<<prefix[i][j]<<"\t";
}
//cout<<endl;
}
cout<<ans<<endl;
}
signed main(){
cin.tie(NULL);
cout.tie(NULL);
//setIO("paintbarn");
ios_base::sync_with_stdio(NULL);
int t=1;
//cin>>t;
while(t--)solve();
return 0;
}
/*
4 4 4 1
....
.M..
..MM
...S
_____
5 5 1 1
....M
.M...
..S..
.S...
...M.
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |