#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
//#define int long long
#define pb push_back
#define F first
#define S second
#define st string
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define mii map<int,int>
#define mll map<ll,ll>
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define yes cout<<"Yes\n";
#define no cout<<"No\n";
#define lf else if
using namespace std;
void why(){
ll n,m,d,k,ans=0,ms=1,sm=0;
cin>>n>>m>>d>>k;
char v[n+7][m+7];
map <pair<ll,ll>,ll> mp;
map <pair<ll,ll>,ll> bp;
ll f[n+7][m+7];
map <pair<ll,ll>,ll> sp;
for(ll i=1;i<=n;i++)
{
for(ll j=1;j<=m;j++)
{
cin>>v[i][j];
if(n==1 && v[i][j]=='S'){ll g=max(j-d,ms),h=min(j+d+1,m);sp[{i,g}]+=1;sp[{i,h}]-=1;}
f[i][j]=0;
if(v[i][j]=='M')mp[{i,j}]+=1;
lf(v[i][j]=='S')bp[{i,j}]+=1;
}
}
if(n!=1)
{
for(auto to : bp)
{
for(auto it : mp)
{
if(it.F.F>to.F.F)ms=it.F.F-to.F.F;
else ms=to.F.F-it.F.F;
if(it.F.S>to.F.S)sm=it.F.S-to.F.S;
else sm=to.F.S-it.F.S;
if(ms<=d && sm<=d)
{
f[it.F.F][it.F.S]+=1;
if(f[it.F.F][it.F.S]==k)ans++;
}
}
}
}
else
{
for(ll i=1;i<=m;i++)
{
if(sp[{1,i}]!=0)sm+=sp[{1,i}];
if(v[1][i]=='M' && sm>=k)
{
ans++;
}
}
}
cout<<ans;
}
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
//srand( time(0));
//freopen("sum.in", "r", stdin);
//freopen("sum.out", "w", stdout);
//ll tests=1;
//cin>>tests;
//for(ll i=1;i<=tests;i++)
//{
//cout<<"Case "<<i<<":\n";
why();
//}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
61 ms |
860 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
61 ms |
860 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
47 ms |
856 KB |
Output is correct |
9 |
Correct |
8 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
16 ms |
720 KB |
Output is correct |
3 |
Correct |
18 ms |
1368 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2140 KB |
Output is correct |
2 |
Correct |
4 ms |
2344 KB |
Output is correct |
3 |
Correct |
4 ms |
2720 KB |
Output is correct |
4 |
Correct |
5 ms |
2140 KB |
Output is correct |
5 |
Correct |
4 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
176 ms |
83284 KB |
Output is correct |
2 |
Correct |
200 ms |
96732 KB |
Output is correct |
3 |
Incorrect |
185 ms |
90552 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
61 ms |
860 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
47 ms |
856 KB |
Output is correct |
9 |
Correct |
8 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
16 ms |
720 KB |
Output is correct |
13 |
Correct |
18 ms |
1368 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
3 ms |
2140 KB |
Output is correct |
17 |
Correct |
4 ms |
2344 KB |
Output is correct |
18 |
Correct |
4 ms |
2720 KB |
Output is correct |
19 |
Correct |
5 ms |
2140 KB |
Output is correct |
20 |
Correct |
4 ms |
2396 KB |
Output is correct |
21 |
Correct |
176 ms |
83284 KB |
Output is correct |
22 |
Correct |
200 ms |
96732 KB |
Output is correct |
23 |
Incorrect |
185 ms |
90552 KB |
Output isn't correct |
24 |
Halted |
0 ms |
0 KB |
- |