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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define pii pair<ll,ll>
#define fi first
#define sec second
#define endl '\n'
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define ordered_multiset tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>
const ll MOD = 998244353;
const ll N = 3e5 + 5;
const ll INF = 1e18;
int32_t main(){
cin.tie(0)->sync_with_stdio(0);
int tc = 1;
// cin >> tc;
while(tc--){
ll r,c,d,s; cin >> r >> c >> d >> s;
char grid[r+5][c+5];
vector<vector<ll>>pref(r+5, vector<ll>(c+5));
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
cin >> grid[i][j];
}
}
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
pref[i][j] = pref[i-1][j] + pref[i][j-1] - pref[i-1][j-1] + (grid[i][j] == 'S');
}
}
ll ans = 0;
for(ll i=1;i<=r;i++){
for(ll j=1;j<=c;j++){
if(grid[i][j] == 'M'){
if(pref[min(r, i+d)][min(c, j+d)] - pref[max(0LL, i-d-1)][j] - pref[i][max(0LL, j-d-1)] + pref[max(0LL, i-d-1)][max(0LL, j-d-1)] >= s) ans++;
}
}
}
cout << ans << 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... |