#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 |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1368 KB |
Output is correct |
2 |
Correct |
2 ms |
1372 KB |
Output is correct |
3 |
Correct |
2 ms |
1628 KB |
Output is correct |
4 |
Correct |
2 ms |
1372 KB |
Output is correct |
5 |
Correct |
2 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
8888 KB |
Output is correct |
2 |
Correct |
12 ms |
12216 KB |
Output is correct |
3 |
Correct |
12 ms |
11960 KB |
Output is correct |
4 |
Correct |
11 ms |
9144 KB |
Output is correct |
5 |
Correct |
19 ms |
13492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
3 ms |
1368 KB |
Output is correct |
17 |
Correct |
2 ms |
1372 KB |
Output is correct |
18 |
Correct |
2 ms |
1628 KB |
Output is correct |
19 |
Correct |
2 ms |
1372 KB |
Output is correct |
20 |
Correct |
2 ms |
1372 KB |
Output is correct |
21 |
Correct |
11 ms |
8888 KB |
Output is correct |
22 |
Correct |
12 ms |
12216 KB |
Output is correct |
23 |
Correct |
12 ms |
11960 KB |
Output is correct |
24 |
Correct |
11 ms |
9144 KB |
Output is correct |
25 |
Correct |
19 ms |
13492 KB |
Output is correct |
26 |
Correct |
10 ms |
5588 KB |
Output is correct |
27 |
Correct |
9 ms |
4884 KB |
Output is correct |
28 |
Correct |
9 ms |
4100 KB |
Output is correct |
29 |
Correct |
8 ms |
4048 KB |
Output is correct |
30 |
Correct |
9 ms |
6352 KB |
Output is correct |