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;
const int MAXN = 5e5+20;
char grid[MAXN];
int pref[MAXN];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int R,C,D,K; cin >> R >> C >> D >> K;
for(int i = 0;i<R;++i){
for(int j = 0;j<C;++j){
cin >> grid[i*C+j];
}
}
for(int i = 0;i<R;++i){
for(int j = 0;j<C;++j){
if(grid[i*C+j] == 'S'){
int r1 = max(0,i-D), r2 = min(R-1,i+D), c1 = max(0,j-D), c2 = min(C-1,j+D);
//cout << r1 << " " << r2 << " " << c1 << " " << c2 << "\n";
pref[r1*C+c1]++;
if(r2 != R-1) pref[(r2+1)*C+c1]--;
if(c2 != C-1) pref[r1*C+c2+1]--;
if(r2 != R-1 && c2 != C-1) pref[(r2+1)*C+c2+1]++;
}
}
}
int ans = 0;
for(int i = 0;i<R;++i){
for(int j = 0;j<C;++j){
if(i) pref[i*C+j] += pref[(i-1)*C+j];
if(j) pref[i*C+j] += pref[i*C+j-1];
if(i > 0 && j > 0) pref[i*C+j] -= pref[(i-1)*C+j-1];
if(grid[i*C+j] == 'M' && pref[i*C+j] >= K){
//cout << pref[i*C+j] << "\n";
ans++;
}
}
}
cout << ans << "\n";
return 0;
}
# | 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... |