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 ll long long
#define ld long double
void solve(){
int R, C, D, S; cin >> R >> C >> D >> S;
vector<pair<int, int>> mushrooms;
vector<vector<int>> P(R + 1, vector<int>(C + 1));
vector<vector<char>> M(R + 1, vector<char>(C + 1));
for(int i = 1; i <= R; ++i){
for(int j = 1; j <= C; ++j){
cin >> M[i][j];
if(M[i][j] == 'M'){
mushrooms.push_back({i, j});
}
else if(M[i][j] == 'S'){
P[i][j] = 1;
}
P[i][j] += P[i][j - 1] + P[i - 1][j] - P[i - 1][j - 1];
}
}
int answer = 0;
for(auto elem : mushrooms){
int x = elem.first, y = elem.second;
int a = max(1, x - D), b = max(1, y - D), c = min(R, x + D), d = min(C, y + D);
//cout << x << " " << y << " " << a << " " << b << " " << c << " " << d << "\n";
if(P[c][d] - P[a - 1][d] - P[c][b - 1] + P[a - 1][b - 1] >= S){
answer++;
}
}
cout << answer;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int tc = 1; //cin >> tc;
while(tc--){
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... |