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;
int main() {
int R,C,D,S;
cin >> R >> C >> D >> S;
string grid[R];
int pref[R+1][C+1];
memset(pref,0,sizeof(pref));
for(int i=0;i<R;i++){
cin >> grid[i];
for(int j=0;j<C;j++){
if(grid[i][j] == 'S'){
int a = max(0,i-D);
int b = min(i+D+1,R);
int c = max(0,j-D);
int d = min(j+D+1,C);
pref[a][c]++;
pref[a][d]--;
pref[b][c]--;
pref[b][d]++;
}
}
}
for(int i=0;i<R;i++){
for(int j=0;j<C;j++){
if(i > 0){
pref[i][j] += pref[i-1][j];
}
if(j > 0){
pref[i][j] += pref[i][j-1];
}
if(i > 0 && j > 0){
pref[i][j] -= pref[i-1][j-1];
}
}
}
int ans = 0;
for(int i=0;i<R;i++){
for(int j=0;j<C;j++){
if(grid[i][j] == 'M' && pref[i][j] >= S){
ans++;
}
}
}
cout << ans << "\n";
}
# | 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... |