#include <bits/stdc++.h>
using namespace std;
int rez=0;
int main()
{
int n,m,d,k;
cin >> n >> m >> d >> k;
char mat1[n][m];
int mat2[n][m];
int f[n][m];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin >> mat1[i][j];
if(mat1[i][j]=='S')mat2[i][j]=1;
else
{
mat2[i][j]=0;
}
}
}
f[0][0]=mat2[0][0];
for(int i=1;i<n;i++)
{
f[i][0]=f[i-1][0]+mat2[i][0];
}
for(int i=1;i<m;i++)
{
f[0][i]=f[0][i-1]+mat2[0][i];
}
for(int i=1;i<n;i++)
{
for(int j=1;j<m;j++)
{
f[i][j]=f[i-1][j]+f[i][j-1]-f[i-1][j-1]+mat2[i][j];
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(mat1[i][j]=='M')
{
int temp=0;
int i1=max(0,i-d);
int j1=max(0,j-d);
int i2=min(n-1,i+d);
int j2=min(m-1,j+d);
temp+=f[i2][j2];
if(i1-1>=0)temp-=f[i1-1][j2];
if(j1-1>=0)temp-=f[i2][j1-1];
if(i1-1>=0 && j2-1>=0)temp+=f[i1-1][j1-1];
if(temp>=k)rez++;
}
}
}
cout << rez;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
424 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
4 ms |
444 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Incorrect |
4 ms |
380 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
2200 KB |
Output is correct |
2 |
Incorrect |
24 ms |
2296 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
5280 KB |
Output is correct |
2 |
Correct |
57 ms |
5264 KB |
Output is correct |
3 |
Correct |
59 ms |
5224 KB |
Output is correct |
4 |
Correct |
58 ms |
5240 KB |
Output is correct |
5 |
Correct |
58 ms |
5172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
424 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
4 ms |
444 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Incorrect |
4 ms |
380 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |