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;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,m,d,k;
cin>>n>>m>>d>>k;
char arr[n+1][m+1];
int pre[n+1][m+1];
int fores[n+1][m+1];
memset(pre,0,sizeof pre);
memset(fores,0,sizeof fores);
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
char a;
cin>>a;
arr[i][j] = a;
if(a=='S'){
fores[max(i-d,1)][max(j-d,1)]++;
fores[min(i+d,n)][min(j+d,m)]--;
}
}
}
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
pre[i][j]=fores[i][j]+pre[i-1][j]+pre[i][j-1]-pre[i-1][j-1];
}
}
int ans=0;
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
if(arr[i][j]=='M'&&pre[i][j]-pre[i-1][j]-pre[i][j-1]+pre[i-1][j-1]>=k){
ans++;
}
}
}
cout<<ans;
}
# | 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... |