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 n,m,a1,b1,a2,b2,d,k;
int main()
{
scanf("%d%d%d%d",&n,&m,&d,&k);
char s[n+5][m+5];
int sweep[n+5][m+5];
memset(sweep,0,sizeof sweep);
for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
//printf("%c",s[i][j]);
if(s[i][j]=='S')
{
a1=max(1,i-d),b1=max(1,j-d);
a2=min(n+1,i+d+1),b2=min(m+1,j+d+1);
//printf("%d %d %d %d\n",a1,b1,a2,b2);
sweep[a1][b1]+=1;
sweep[a1][b2]-=1,sweep[a2][b1]-=1,sweep[a2][b2]+=1;
}
}
//printf("\n");
}
int ans=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
sweep[i][j]=sweep[i][j]+sweep[i-1][j]+sweep[i][j-1]-sweep[i-1][j-1];
if(sweep[i][j]>=k&&s[i][j]=='M')++ans;
//printf("%d ",sweep[i][j]);
}
// printf("\n");
}
printf("%d\n",ans);
}
Compilation message (stderr)
mushrooms.cpp: In function 'int main()':
mushrooms.cpp:7:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
7 | scanf("%d%d%d%d",&n,&m,&d,&k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
mushrooms.cpp:11:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
| ~~~~~^~~~~~~~~~~~~
# | 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... |