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>
#define int long long int
using namespace std;
signed main(){
int r,c,d,k; cin >> r >> c >> d >> k;
char a[r+1][c+1];
int pre[r+1][c+1];
for (int i = 1; i <= r; i++){
for (int j = 1; j <= c; j++){
cin >> a[i][j];
}
}
for (int i = 0; i <= r; i++){
for (int j = 0; j <= c; j++) pre[i][j] = 0;
}
for (int i = 1; i <= r; i++){
for (int j = 1; j <= c; j++){
pre[i][j] = (pre[i-1][j]+pre[i][j-1]+(a[i][j] == 'S'))-pre[i-1][j-1];
}
}
int cnt = 0;
for (int i = 1; i <= r; i++){
for (int j = 1; j <= c; j++){
if (a[i][j] != 'M') continue;
int u = max(i-d,1LL);
int v = max(j-d, 1LL);
int w = min(i+d, r);
int x = min(j+d, c);
int cur = pre[w][x]-pre[u-1][x]-pre[w][v-1]+pre[u-1][v-1];
if (cur >= k) cnt++;
}
}
cout << cnt << 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... |