이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pp pop_back
#define mp make_pair
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pii pair<int,int> 
#define vl vector<ll> 
#define nikah ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll maxn = 5e5+7, modn1 = 1e9+7, modn2 = 998244353;
using namespace std;
// kalo kamu ngga emas nanti nadya merasa bersalah, ayo san demi nadya!!!
// Kalo emang soalnya susah, pindah soal dulu 
// Jangan sampe diem, pikirin sesuatu, pasti bisa!!!
// Cobain semua approach, jangan ngestuck di satu pemikiran
// Jangan overthinking, jangan panik, tenangin pikiranmu
ll t,r,c,d,s;
vector<ll>a,b,e,f;
bool binser1(ll x) {
  ll l = 0, r = e.size()-1;
  while (l <= r) {
    ll mid = (l+r)/2;
    ll dis = e[mid] - x;
    if (abs(dis) <= d) {
      return 1;
    }
    if (dis > 0) {
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  return 0;
}
bool binser2(ll x) {
  ll l = 0, r = f.size()-1;
  while (l <= r) {
    ll mid = (l+r)/2;
    ll dis = f[mid] - x;
    if (abs(dis) <= d) {
      return 1;
    }
    if (dis > 0) {
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  return 0;
}
void solve() {
  cin>>r>>c>>d>>s;
  for (ll i=1; i<=r; i++) {
    for (ll j=1; j<=c; j++) {
      char x; cin>>x;
      if (x == 'M') {
        a.pb(i);
        b.pb(j);
      } else if (x == 'S') {
        e.pb(i);
        f.pb(j);
      }
    }
  }
  sort(f.begin(),f.end()); sort(e.begin(),e.end());
  ll ans = 0;
  for (ll i=0; i<a.size(); i++) {
    if (binser1(a[i]) && binser2(b[i])) {
      ans++;
    }
  }
  cout<<ans;
}
int main () {
  nikah
  t = 1;
//  cin>>t;
  while (t--) {
    solve();
  //  cout<<endl;
  }
}
컴파일 시 표준 에러 (stderr) 메시지
mushrooms.cpp: In function 'void solve()':
mushrooms.cpp:76:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |   for (ll i=0; i<a.size(); i++) {
      |                ~^~~~~~~~~| # | 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... |