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 (){
int r,c,d,k;
cin>>r>>c>>d>>k;
char grid[r+1][c+1];
for(int i=1;i<=r;i++)
{
for(int j=1;j<=c;j++)
{
cin>>grid[i][j];
}
}
int sprinkles[r+1][c+1];
for (int i=0;i<=r;i++)
{
for (int j=0;j<=c;j++)
{
if(i==0 || j==0)
{
sprinkles[i][j]=0;
continue;
}
sprinkles[i][j]=0;
sprinkles[i][j]+=sprinkles[i-1][j];
sprinkles[i][j]+=sprinkles[i][j-1];
sprinkles[i][j]-=sprinkles[i-1][j-1];
if(grid[i][j]=='S'){
sprinkles[i][j]++;
}
}
}
int res = 0;
for(int i=1;i<=r;i++)
{
for(int j=1;j<=c;j++)
{
if(grid[i][j]=='M'){
int i1 , j1 , i2 , j2;
if(i-d-1>=0) i1=i-d-1;
else i1=0;
if(i+d<=r) i2=i+d;
else i2=r;
if(j-1-d>=0) j1=j-d-1;
else j1=0;
if(j+d<=c) j2=j+d;
else j2=c;
if(sprinkles[i2][j2]-sprinkles[i1][j1]>=k)
res++;
}
}
}
cout<<res<<endl;
return 0;
}
# | 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... |