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>
#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=0,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];
for(ll i=1;i<=n;i++)
{
for(ll j=1;j<=m;j++)
{
cin>>v[i][j];
f[i][j]=0;
if(v[i][j]=='M')mp[{i,j}]+=1;
lf(v[i][j]=='S')bp[{i,j}]+=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++;
}
}
}
cout<<ans;
}
signed main(){
ios_base::sync_with_stdio(0),cin.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();
}
}
# | 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... |