This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
ID: samikgo1
TASK:
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define f first
#define s second
//#define x first
//#define y second
const int INF = INT32_MAX;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("haybales.in","r",stdin);
// freopen("haybales.out","w",stdout);
ll r,c,d,k;
cin >> r >> c >> d >> k;
char grid[r+1][c+1];
vector<vector<ll>> prefix(r+1,vector<ll>(c+1));
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
prefix[i][j] = prefix[i-1][j] + prefix[i][j-1] - prefix[i-1][j-1];
cin>>grid[i][j];
if(grid[i][j]=='S')prefix[i][j]++;
}
}
ll ans = 0;
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
if(grid[i][j]!='M')continue;
ll pre = prefix[min(i+d,r)][min(j+d,c)]+prefix[max(i-d-1,(ll)0)][max(j-d-1,(ll)0)] - prefix[max(i-d-1,(ll)0)][min(j+d,c)] - prefix[min(i+d,r)][max(j-d-1,(ll)0)];
if(pre>=k)ans++;
}
}
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... |