#include <bits/stdc++.h>
#define ll long long
#define KAGAMINE ios_base::sync_with_stdio(false);
#define LEN cin.tie(NULL);
#define slv solve();
#define slve int tc = 1; cin >> tc; while(tc--){solve();}
#define pls cout << "mantap\n";
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define pb push_back
#define vector2d(x) vector<vector<x>>
#define pii pair<int, int>
#define pl pair<ll, ll>
using namespace std;
int r, c, d, k;
vector2d(int) jrk;
vector<pii> mus, spr;
void sub5(){
vector<int> kor;
for (int i = 0; i < spr.size(); i++){
kor.pb(spr[i].se);
}
sort(all(kor));
// for (auto x : kor) cout << x << " ";
// cout << "\n";
int ans = 0;
for (int i = 0; i < mus.size(); i++){
int rn = mus[i].se;
auto lb = lower_bound(all(kor),rn-d),
ub = upper_bound(all(kor), rn+d);
int cnt = ub-lb;
// cout << ka << " " << ki << "\n";
if (cnt >= k) ans++;
}
cout << ans;
}
void sub3(){
}
int main(){
KAGAMINE LEN
cin >> r >> c >> d >> k;
for (int i = 0; i < r; i++){
for (int j = 0; j < c; j++){
char tmp; cin >> tmp;
if (tmp == 'S') spr.pb({i,j});
if (tmp == 'M') mus.pb({i,j});
}
}
if (d == max(r,c) && k == 1){ // subtsk 1
cout << mus.size();
return 0;
}
if (d == max(r,c)){ // subtsk 2
if (spr.size() >= k){
cout << mus.size();
}
else {
cout << 0;
}
return 0;
}
if (r == 1){
sub5();
return 0;
}
sub3();
return 0;
}
# | 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... |