#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
int main(void)
{
int r, c, d, k; cin >> r >> c >> d >> k;
vector<pair<int, int>> v;
vector<pair<int, int>> s;
char x;
for(int i = 1; i <= r; i++)
{
for(int j = 1; j <= c; j++)
{
cin >> x;
if(x == 'M') v.push_back(make_pair(i, j));
if(x == 'S') s.push_back(make_pair(i, j));
}
}
int a[r + 2][c + 2] = {};
for(auto u : s)
{
// cout << u.fi << " " << u.se << endl;
int f = u.se - d;
// cout << max(1, u.fi - d) << " " << min(r, u.fi + d) << endl;
for(int i = max(1, u.fi - d); i <= min(r, u.fi + d); i++)
{
a[i][max(1, u.se - d)]++;
a[i][min(c + 1, u.se + d + 1)]--;
}
}
for(int i = 1; i <= r; i++)
for(int j = 1; j <= c; j++)
a[i][j] += a[i][j - 1];
// for(int i = 1; i <= r + 1; i++) { for(int j = 1; j <= c + 1; j++) cout << a[i][j] << " "; cout << endl; }
int ans = 0;
for(auto u : v) if(a[u.fi][u.se] >= k) ans++;
cout << ans << endl;
}
Compilation message
mushrooms.cpp: In function 'int main()':
mushrooms.cpp:31:13: warning: unused variable 'f' [-Wunused-variable]
int f = u.se - d;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
356 KB |
Output is correct |
8 |
Correct |
4 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
380 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
1400 KB |
Output is correct |
2 |
Correct |
23 ms |
1272 KB |
Output is correct |
3 |
Correct |
28 ms |
1532 KB |
Output is correct |
4 |
Correct |
24 ms |
1372 KB |
Output is correct |
5 |
Correct |
24 ms |
1400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
9688 KB |
Output is correct |
2 |
Correct |
67 ms |
10516 KB |
Output is correct |
3 |
Correct |
69 ms |
9960 KB |
Output is correct |
4 |
Correct |
71 ms |
10336 KB |
Output is correct |
5 |
Correct |
69 ms |
11660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
356 KB |
Output is correct |
8 |
Correct |
4 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
380 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
3 ms |
504 KB |
Output is correct |
16 |
Correct |
22 ms |
1400 KB |
Output is correct |
17 |
Correct |
23 ms |
1272 KB |
Output is correct |
18 |
Correct |
28 ms |
1532 KB |
Output is correct |
19 |
Correct |
24 ms |
1372 KB |
Output is correct |
20 |
Correct |
24 ms |
1400 KB |
Output is correct |
21 |
Correct |
64 ms |
9688 KB |
Output is correct |
22 |
Correct |
67 ms |
10516 KB |
Output is correct |
23 |
Correct |
69 ms |
9960 KB |
Output is correct |
24 |
Correct |
71 ms |
10336 KB |
Output is correct |
25 |
Correct |
69 ms |
11660 KB |
Output is correct |
26 |
Execution timed out |
2025 ms |
5200 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |