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 ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fs first
#define sc second
#define pb push_back
void solve() {
int n,m,d,k;
cin>>n>>m>>d>>k;
int a[n+1][m+1];
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
char c;
cin>>c;
if(c=='.')a[i][j]=0;
else if(c=='M')a[i][j]=1;
else a[i][j]=2;
}
}
int pre[n+1][m+1];
memset(pre,0,sizeof(pre));
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j]==2){
pre[max(1,i-d)][max(1,j-d)]++;
if(i+d+1<=n)pre[i+d+1][max(1,j-d)]--;
if(j+d+1<=m)pre[max(1,i-d)][j+d+1]--;
if(i+d+1<=n&&j+d+1<=m)pre[i+d+1][j+d+1]++;
}
}
}
int ans=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
pre[i][j]+=pre[i-1][j]+pre[i][j-1]-pre[i-1][j-1];
ans+=a[i][j]==1&&pre[i][j]>=k;
}
}
cout<<ans;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
}
# | 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... |