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>
using namespace std;
#define int long long
void solve(){
int R, C;
cin >>R>>C;
int D, K;
cin >>D >>K;
vector <vector <int>> pref(R+1, vector <int> (C+1,0));
vector <pair<int,int>> loc;
for(int i=1; i<=R; i++){
string a;
cin >>a;
for(int j=1; j<=C; j++){
char x = a[j-1];
pref[i][j]=pref[i][j-1]+pref[i-1][j]-pref[i-1][j-1];
if(x=='M') loc.push_back(make_pair(i,j));
if(x=='S'){
pref[i][j]++;
}
}
}
int ans = 0;
for(auto x: loc){
pair maxpos =make_pair(min(R,x.first+D), min(C,x.second+D));
pair minpos =make_pair(max(1ll,x.first-D), max(1ll,x.second-D));
int n = pref[maxpos.first][maxpos.second]-pref[minpos.first-1][maxpos.second]-pref[maxpos.first][minpos.second-1]+pref[minpos.first-1][minpos.second-1];
if(K<=n) ans++;
}
cout <<ans<<endl;
}
signed main(){
int t; cin >>t;
while(t--){
solve();
}
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... |