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>
using namespace std;
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
//#define int ll
#define sz size()
#define x first
#define y second
#define pi pair <int, int>
#define pii pair <int, pi>
#define vi vector <int>
const ll mod = 998244353;
int n, m, d, k;
int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
cin>>n>>m>>d>>k;
int t[n+2][m+2];
bool ms[n+2][m+2];
for(int i=1; i<=n; i++) for(int j=0; j<=m; j++) ms[i][j]=0;
for(int i=0; i<=n; i++) for(int j=0; j<=m; j++) t[i][j]=0;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
char c;
cin>>c;
if(c=='M') ms[i][j]=1;
else if(c=='S'){
t[max(i-d, 1)][max(j-d, 1)]++;
t[min(i+d+1, n+1)][max(j-d, 1)]--;
t[max(i-d, 1)][min(j+d+1, m+1)]--;
t[min(i+d+1, n+1)][min(j+d+1, m+1)]++;
}
}
}
int ans=0;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
t[i][j]+=t[i-1][j]+t[i][j-1]-t[i-1][j-1];
//cout<<t[i][j]<<" ";
if(ms[i][j] && t[i][j]>=k) ans++;
}
//cout<<endl;
}
cout<<ans;
}
# | 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... |