#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lld long long double
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(a) a.begin(), a.end()
#define IShowSpeed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int N=5e5+100;
const int mod=1e9+7;
const int K=500;
const ll inf=1e18+1337;
const int dx[]={-1, 0, 0, 1};
const int dy[]={0, -1, 1, 0};
vector<ll>h[N];
vector< pair<ll,ll> >v;
int main()
{
IShowSpeed
ll n,m,d,k,ans=0;
cin>>n>>m>>d>>k;
for(int i=0;i<=n;i++)
for(int j=0;j<=m;j++)
h[i].pb(0);
for(int i=1;i<=n;++i)
{
for(int j=1;j<=m;++j)
{
char c;
cin>>c;
h[i][j]=h[i-1][j]+h[i][j-1]-h[i-1][j-1];
if(c=='S') h[i][j]++;
if(c=='M') v.pb({i,j});
}
}
for(auto p: v)
{
ll x=p.F,y=p.S;
ll x1=max(0ll,x-d-1),x2=min(n,x+d);
ll y1=max(0ll,y-d-1),y2=min(m,y+d);
if(h[x2][y2]-h[x2][y1]-h[x1][y2]+h[x1][y1]>=k) ans++;
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12124 KB |
Output is correct |
2 |
Correct |
3 ms |
12400 KB |
Output is correct |
3 |
Correct |
3 ms |
12380 KB |
Output is correct |
4 |
Correct |
3 ms |
12124 KB |
Output is correct |
5 |
Correct |
3 ms |
12124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12124 KB |
Output is correct |
2 |
Correct |
3 ms |
12400 KB |
Output is correct |
3 |
Correct |
3 ms |
12380 KB |
Output is correct |
4 |
Correct |
3 ms |
12124 KB |
Output is correct |
5 |
Correct |
3 ms |
12124 KB |
Output is correct |
6 |
Correct |
3 ms |
12124 KB |
Output is correct |
7 |
Correct |
3 ms |
12124 KB |
Output is correct |
8 |
Correct |
3 ms |
12380 KB |
Output is correct |
9 |
Correct |
3 ms |
12124 KB |
Output is correct |
10 |
Correct |
3 ms |
12124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12124 KB |
Output is correct |
2 |
Correct |
3 ms |
12124 KB |
Output is correct |
3 |
Correct |
3 ms |
12636 KB |
Output is correct |
4 |
Correct |
3 ms |
12124 KB |
Output is correct |
5 |
Correct |
3 ms |
12456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
13916 KB |
Output is correct |
2 |
Correct |
8 ms |
14168 KB |
Output is correct |
3 |
Correct |
8 ms |
14680 KB |
Output is correct |
4 |
Correct |
7 ms |
13916 KB |
Output is correct |
5 |
Correct |
9 ms |
14428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
28072 KB |
Output is correct |
2 |
Correct |
21 ms |
28972 KB |
Output is correct |
3 |
Correct |
20 ms |
29400 KB |
Output is correct |
4 |
Correct |
18 ms |
27476 KB |
Output is correct |
5 |
Correct |
21 ms |
29912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12124 KB |
Output is correct |
2 |
Correct |
3 ms |
12400 KB |
Output is correct |
3 |
Correct |
3 ms |
12380 KB |
Output is correct |
4 |
Correct |
3 ms |
12124 KB |
Output is correct |
5 |
Correct |
3 ms |
12124 KB |
Output is correct |
6 |
Correct |
3 ms |
12124 KB |
Output is correct |
7 |
Correct |
3 ms |
12124 KB |
Output is correct |
8 |
Correct |
3 ms |
12380 KB |
Output is correct |
9 |
Correct |
3 ms |
12124 KB |
Output is correct |
10 |
Correct |
3 ms |
12124 KB |
Output is correct |
11 |
Correct |
3 ms |
12124 KB |
Output is correct |
12 |
Correct |
3 ms |
12124 KB |
Output is correct |
13 |
Correct |
3 ms |
12636 KB |
Output is correct |
14 |
Correct |
3 ms |
12124 KB |
Output is correct |
15 |
Correct |
3 ms |
12456 KB |
Output is correct |
16 |
Correct |
8 ms |
13916 KB |
Output is correct |
17 |
Correct |
8 ms |
14168 KB |
Output is correct |
18 |
Correct |
8 ms |
14680 KB |
Output is correct |
19 |
Correct |
7 ms |
13916 KB |
Output is correct |
20 |
Correct |
9 ms |
14428 KB |
Output is correct |
21 |
Correct |
18 ms |
28072 KB |
Output is correct |
22 |
Correct |
21 ms |
28972 KB |
Output is correct |
23 |
Correct |
20 ms |
29400 KB |
Output is correct |
24 |
Correct |
18 ms |
27476 KB |
Output is correct |
25 |
Correct |
21 ms |
29912 KB |
Output is correct |
26 |
Correct |
18 ms |
20948 KB |
Output is correct |
27 |
Correct |
16 ms |
22764 KB |
Output is correct |
28 |
Correct |
14 ms |
18640 KB |
Output is correct |
29 |
Correct |
13 ms |
18896 KB |
Output is correct |
30 |
Correct |
17 ms |
22368 KB |
Output is correct |