#include <bits/stdc++.h>
using namespace std;
#define int long long
int r, c, d, s, jum;
vector<pair<int, int>> v;
signed main() {
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin >> r >> c >> d >> s;
char arr[r + 5][c + 5];
int pref[r + 5][c + 5];
for(int i = 1; i <= r; i++) {
for(int j = 1; j <= c; j++) {
cin >> arr[i][j];
if(arr[i][j] == 'M') {
v.push_back({i, j});
}
}
}
for(int i = 1; i <= r; i++) {
for(int j = 1; j <= c; j++) {
if(arr[i][j] == 'S') {
pref[i][j] = pref[i][j - 1] + pref[i - 1][j] - pref[i - 1][j - 1] + 1;
} else {
pref[i][j] = pref[i][j - 1] + pref[i - 1][j] - pref[i - 1][j - 1];
}
}
}
for(int i = 0; i < v.size(); i++) {
int a = v[i].first, b = v[i].second;
int lr, lc, hr, hc;
lr = max(0ll, a - d - 1);
lc = max(0ll, b - d - 1);
hr = min(r, a + d);
hc = min(c, b + d);
int funi = pref[hr][hc] - pref[lr][hc] - pref[hr][lc] + pref[lr][lc];
if(funi >= s) {
jum++;
}
}
cout << jum << "\n";
}
Compilation message
mushrooms.cpp: In function 'int main()':
mushrooms.cpp:28:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for(int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 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 |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 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 |
1 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 |
860 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2140 KB |
Output is correct |
2 |
Correct |
3 ms |
2288 KB |
Output is correct |
3 |
Correct |
4 ms |
2652 KB |
Output is correct |
4 |
Correct |
3 ms |
2304 KB |
Output is correct |
5 |
Correct |
4 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
31388 KB |
Output is correct |
2 |
Correct |
25 ms |
35832 KB |
Output is correct |
3 |
Correct |
24 ms |
36048 KB |
Output is correct |
4 |
Correct |
23 ms |
32980 KB |
Output is correct |
5 |
Correct |
26 ms |
35784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 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 |
1 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 |
860 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
716 KB |
Output is correct |
16 |
Correct |
4 ms |
2140 KB |
Output is correct |
17 |
Correct |
3 ms |
2288 KB |
Output is correct |
18 |
Correct |
4 ms |
2652 KB |
Output is correct |
19 |
Correct |
3 ms |
2304 KB |
Output is correct |
20 |
Correct |
4 ms |
2396 KB |
Output is correct |
21 |
Correct |
22 ms |
31388 KB |
Output is correct |
22 |
Correct |
25 ms |
35832 KB |
Output is correct |
23 |
Correct |
24 ms |
36048 KB |
Output is correct |
24 |
Correct |
23 ms |
32980 KB |
Output is correct |
25 |
Correct |
26 ms |
35784 KB |
Output is correct |
26 |
Correct |
11 ms |
7892 KB |
Output is correct |
27 |
Correct |
12 ms |
10708 KB |
Output is correct |
28 |
Correct |
10 ms |
7384 KB |
Output is correct |
29 |
Correct |
10 ms |
7384 KB |
Output is correct |
30 |
Correct |
13 ms |
11592 KB |
Output is correct |