#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5+20;
char grid[MAXN];
int pref[MAXN];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int R,C,D,K; cin >> R >> C >> D >> K;
for(int i = 0;i<R;++i){
for(int j = 0;j<C;++j){
cin >> grid[i*C+j];
}
}
for(int i = 0;i<R;++i){
for(int j = 0;j<C;++j){
if(grid[i*C+j] == 'S'){
int r1 = max(0,i-D), r2 = min(R-1,i+D), c1 = max(0,j-D), c2 = min(C-1,j+D);
//cout << r1 << " " << r2 << " " << c1 << " " << c2 << "\n";
pref[r1*C+c1]++;
if(r2 != R-1) pref[(r2+1)*C+c1]--;
if(c2 != C-1) pref[r1*C+c2+1]--;
if(r2 != R-1 && c2 != C-1) pref[(r2+1)*C+c2+1]++;
}
}
}
int ans = 0;
for(int i = 0;i<R;++i){
for(int j = 0;j<C;++j){
if(i) pref[i*C+j] += pref[(i-1)*C+j];
if(j) pref[i*C+j] += pref[i*C+j-1];
if(i > 0 && j > 0) pref[i*C+j] -= pref[(i-1)*C+j-1];
if(grid[i*C+j] == 'M' && pref[i*C+j] >= K){
//cout << pref[i*C+j] << "\n";
ans++;
}
}
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2400 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2716 KB |
Output is correct |
2 |
Correct |
4 ms |
2736 KB |
Output is correct |
3 |
Correct |
3 ms |
2908 KB |
Output is correct |
4 |
Correct |
3 ms |
2784 KB |
Output is correct |
5 |
Correct |
3 ms |
2784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
3164 KB |
Output is correct |
2 |
Correct |
6 ms |
3364 KB |
Output is correct |
3 |
Correct |
8 ms |
3164 KB |
Output is correct |
4 |
Correct |
7 ms |
3164 KB |
Output is correct |
5 |
Correct |
7 ms |
3400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2400 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
3 ms |
2716 KB |
Output is correct |
17 |
Correct |
4 ms |
2736 KB |
Output is correct |
18 |
Correct |
3 ms |
2908 KB |
Output is correct |
19 |
Correct |
3 ms |
2784 KB |
Output is correct |
20 |
Correct |
3 ms |
2784 KB |
Output is correct |
21 |
Correct |
8 ms |
3164 KB |
Output is correct |
22 |
Correct |
6 ms |
3364 KB |
Output is correct |
23 |
Correct |
8 ms |
3164 KB |
Output is correct |
24 |
Correct |
7 ms |
3164 KB |
Output is correct |
25 |
Correct |
7 ms |
3400 KB |
Output is correct |
26 |
Correct |
8 ms |
3160 KB |
Output is correct |
27 |
Correct |
9 ms |
3272 KB |
Output is correct |
28 |
Correct |
8 ms |
3164 KB |
Output is correct |
29 |
Correct |
8 ms |
3164 KB |
Output is correct |
30 |
Correct |
8 ms |
3420 KB |
Output is correct |