# include <bits/stdc++.h>
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<
int,
null_type,
less_equal<int>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
# define ll long long
# define flp(i, n) for (int i = 0; i < n; i++)
# define endl "\n"
# define TEST int t; cin >> t; while (t--)
# define MOD 1000000007
# define all(x) x.begin(), x.end()
# define print(x) for (auto i : x) cout << i << " ";\
cout << endl;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int r, c, d, k;
cin >> r >> c >> d >> k;
char arr[r + 1][c + 1];
for (int i = 1; i <= r; i++) for (int j = 1; j <= c;j++) cin >> arr[i][j];
int dp[r + 2][c + 2];
memset(dp, 0, sizeof dp);
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
if (arr[i][j] == 'S') {
dp[max(1, i - d)][max(1, j - d)]++;
dp[min(r,i + d) + 1][min(c,j + d) + 1]++;
dp[min(r,i + d) + 1][max(1, j - d)]--;
dp[max(1, i - d)][min(c, j + d) + 1]--;
}
}
}
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) dp[i][j] += dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
}
int cnt = 0;
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
if (arr[i][j] == 'M') if (dp[i][j] >= k) cnt++;
}
}
cout << cnt << endl;
return 0;
}
Compilation message
mushrooms.cpp:21: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
21 | #pragma GCC optimization ("O3")
|
mushrooms.cpp:22: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
22 | #pragma GCC optimization ("unroll-loops")
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1484 KB |
Output is correct |
2 |
Correct |
5 ms |
1484 KB |
Output is correct |
3 |
Correct |
6 ms |
1704 KB |
Output is correct |
4 |
Correct |
5 ms |
1484 KB |
Output is correct |
5 |
Correct |
6 ms |
1484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
7116 KB |
Output is correct |
2 |
Correct |
14 ms |
7116 KB |
Output is correct |
3 |
Correct |
15 ms |
7092 KB |
Output is correct |
4 |
Correct |
16 ms |
7116 KB |
Output is correct |
5 |
Correct |
15 ms |
7116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
312 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
5 ms |
1484 KB |
Output is correct |
17 |
Correct |
5 ms |
1484 KB |
Output is correct |
18 |
Correct |
6 ms |
1704 KB |
Output is correct |
19 |
Correct |
5 ms |
1484 KB |
Output is correct |
20 |
Correct |
6 ms |
1484 KB |
Output is correct |
21 |
Correct |
15 ms |
7116 KB |
Output is correct |
22 |
Correct |
14 ms |
7116 KB |
Output is correct |
23 |
Correct |
15 ms |
7092 KB |
Output is correct |
24 |
Correct |
16 ms |
7116 KB |
Output is correct |
25 |
Correct |
15 ms |
7116 KB |
Output is correct |
26 |
Correct |
14 ms |
3276 KB |
Output is correct |
27 |
Correct |
14 ms |
3148 KB |
Output is correct |
28 |
Correct |
16 ms |
3276 KB |
Output is correct |
29 |
Correct |
13 ms |
3276 KB |
Output is correct |
30 |
Correct |
13 ms |
3276 KB |
Output is correct |