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 <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <vector>
#include <random>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[8]={-1,0,1,0,1,1,-1,-1},dy[8]={0,1,0,-1,1,-1,1,-1};
vi vin(int n,int d=0){
vi a(n);
for(int i=0;i<n;i++){
cin>>a[i];
a[i]-=d;
}
return a;
}
vl vlin(int n,int d=0){
vl a(n);
for(auto &i:a){
cin>>i;
i-=d;
}
return a;
}
vvi vvin(int n,int m){
vvi a(n,vi(m));
for(int i=0;i<n;i++) for(auto &j:a[i]) cin>>j;
return a;
}
vvi gin(int n,int m,int d=1){
vvi g(n);
for(int i=0;i<m;i++){
int u,v;
cin>>u>>v;
u-=d,v-=d;
g[u].push_back(v);
g[v].push_back(u);
}
return g;
}
void vout(vi a){
int n=a.size();
cout<<n<<" :";
for(auto i:a) cout<<' '<<i;
cout<<endl;
}
void vvout(vvi a){
int n=a.size();
for(int i=0;i<n;i++) vout(a[i]);
}
bool ingrid(int x,int y,int n,int m){
return 0<=x&&x<n&&0<=y&&y<m;
}
int readInt() {
int x=0;
char ch=getchar_unlocked();
bool s=1;
while(ch<'0'||ch>'9'){if(ch=='-')s=0;ch=getchar_unlocked();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar_unlocked();}
return s?x:-x;
}
int h,w,d,m;
int main(){
cin>>h>>w>>d>>m;
vs a(h);
vvi b(h+1,vi(w+1));
for(auto &i:a) cin>>i;
for(int i=0;i<h;i++) for(int j=0;j<w;j++) if(a[i][j]=='S'){
int x=max(i-d,0),y=max(j-d,0),X=min(h,i+d+1),Y=min(w,j+d+1);
b[x][y]++;
b[x][Y]--;
b[X][y]--;
b[X][Y]++;
}
int t=0;
for(int i=0;i<h;i++) for(int j=0;j<w;j++){
if(i) b[i][j]+=b[i-1][j];
if(j) b[i][j]+=b[i][j-1];
if(i&&j) b[i][j]-=b[i-1][j-1];
if(a[i][j]=='M'&&b[i][j]>=m) t++;
}
cout<<t<<endl;
}
# | 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... |