#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
signed main()
{
int r, c, d, p, ans=0;
scanf("%lld %lld %lld %lld", &r, &c, &d, &p);
char s[r+5][c+5];
int pref[r+5][c+5];
vector<pair<int, int> >v;
memset(pref, 0, sizeof(pref));
for(int i=1; i<=r; i++)
{
for(int j=1; j<=c; j++)
{
scanf(" %c", &s[i][j]);
// printf("%c\n", s[i][j]);
if(s[i][j]=='M')
{
v.push_back({i, j});
}
if(s[i][j]=='S')pref[i][j]++;
pref[i][j]+=(pref[i-1][j]+pref[i][j-1]);
pref[i][j]-=pref[i-1][j-1];
}
}
// for(int i=1; i<=r; i++)
// {
// for(int j=1; j<=c; j++)
// {
// printf("%d ", pref[i][j]);
// }
// printf("\n");
// }
for(int i=0; i<v.size(); i++)
{
// printf("%lld\n", pref[min(r, v[i].fi+d)][min(c, v[i].se+d)]-pref[max(0ll, v[i].fi-d-1)][min(c, v[i].se+d)]-pref[min(r, v[i].fi+d)][max(0ll, v[i].se-d-1)]+pref[max(0ll, v[i].fi-d-1)][max(0ll, v[i].se-d-1)]);
if(pref[min(r, v[i].fi+d)][min(c, v[i].se+d)]-pref[max(0ll, v[i].fi-d-1)][min(c, v[i].se+d)]-pref[min(r, v[i].fi+d)][max(0ll, v[i].se-d-1)]+pref[max(0ll, v[i].fi-d-1)][max(0ll, v[i].se-d-1)]>=p)
{
ans++;
}
}
printf("%lld\n", ans);
}
Compilation message
mushrooms.cpp: In function 'int main()':
mushrooms.cpp:37:17: 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]
37 | for(int i=0; i<v.size(); i++)
| ~^~~~~~~~~
mushrooms.cpp:9:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
9 | scanf("%lld %lld %lld %lld", &r, &c, &d, &p);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mushrooms.cpp:18:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf(" %c", &s[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 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 |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
1112 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2396 KB |
Output is correct |
2 |
Correct |
7 ms |
2372 KB |
Output is correct |
3 |
Correct |
9 ms |
2788 KB |
Output is correct |
4 |
Correct |
7 ms |
2496 KB |
Output is correct |
5 |
Correct |
13 ms |
2904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
32708 KB |
Output is correct |
2 |
Correct |
33 ms |
35516 KB |
Output is correct |
3 |
Correct |
43 ms |
35776 KB |
Output is correct |
4 |
Correct |
31 ms |
33228 KB |
Output is correct |
5 |
Correct |
35 ms |
37056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 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 |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
1112 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
7 ms |
2396 KB |
Output is correct |
17 |
Correct |
7 ms |
2372 KB |
Output is correct |
18 |
Correct |
9 ms |
2788 KB |
Output is correct |
19 |
Correct |
7 ms |
2496 KB |
Output is correct |
20 |
Correct |
13 ms |
2904 KB |
Output is correct |
21 |
Correct |
32 ms |
32708 KB |
Output is correct |
22 |
Correct |
33 ms |
35516 KB |
Output is correct |
23 |
Correct |
43 ms |
35776 KB |
Output is correct |
24 |
Correct |
31 ms |
33228 KB |
Output is correct |
25 |
Correct |
35 ms |
37056 KB |
Output is correct |
26 |
Correct |
25 ms |
8140 KB |
Output is correct |
27 |
Correct |
27 ms |
10700 KB |
Output is correct |
28 |
Correct |
21 ms |
7884 KB |
Output is correct |
29 |
Correct |
23 ms |
7888 KB |
Output is correct |
30 |
Correct |
22 ms |
11072 KB |
Output is correct |