이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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+d] - pref[i+d][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... |