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>
#pragma optimize("Ofast")
#pragma target("avx2")
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define mem(a,i) memset(a,i,sizeof(a))
#define sz(s) (int)s.size()
#define y1 yy
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b) __gcd(a,b)
#define in insert
#define int ll
const int MAX=5e5+5;
const int B=90;
const int N=105;
const int block=400;
const int maxB=MAX/B+10;
const ll inf=2e18;
const int mod=998244353;
const int mod1=1e9+9;
const ld eps=1e-9;
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,-1,1,-1};
int binpow(int a,int n){
if(!n)return 1;
if(n%2==1)return a*binpow(a,n-1)%mod;
int k=binpow(a,n/2);
return k*k%mod;
}
int r,c,d,k;
int f[MAX];
void solve(){
cin>>r>>c>>d>>k;
vector<vector<int>> a,b;
a.resize(r+5);
b.resize(r+5);
for(int i=1;i<=r;i++){
a[i].resize(c+5);
b[i].resize(c+5);
}
// cout<<r<<" "<<c<<"\n";
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
char x;
cin>>x;
if(x=='.')a[i][j]=0;
else if(x=='M')a[i][j]=1;
else{
a[i][j]=2;
int lx=max(1ll,i-d);
int rx=min(r,i+d);
int ly=max(1ll,j-d);
int ry=min(c,j+d);
// cerr<<lx<<" "<<rx<<" "<<ly<<" "<<ry<<"\n";
b[lx][ly]++;
if(ry+1<=c)b[lx][ry+1]--;
// cerr<<rx+1<<" "<<r<<"\n";
// cerr<<sz(b)<<" "<<sz(b[rx+1])<<"\n";
if(rx+1<=r)b[rx+1][ly]--;
// cerr<<lx<<" "<<rx<<" "<<ly<<" "<<ry<<"\n";
if(rx+1<=r&&ry+1<=c)b[rx+1][ry+1]++;
}
}
}
int ans=0;
for(int i=1;i<=r;i++){
int cnt=0;
// cout<<i<<" "<<c<<"\n";
for(int j=1;j<=c;j++){
// cout<<i<<" "<<j<<" "<<c<<"\n";
f[j]+=b[i][j];
cnt+=f[j];
if(cnt>=k&&a[i][j]==1)ans++;
}
}
cout<<ans;
}
signed main(){
// freopen("help.in","r",stdin);
// freopen("help.out","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// prec();
int t=1;
// cin>>t;
while(t--)solve();
}
Compilation message (stderr)
mushrooms.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
3 | #pragma optimize("Ofast")
|
mushrooms.cpp:4: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
4 | #pragma target("avx2")
|
# | 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... |