#include <bits/stdc++.h>
using namespace std;
vector<vector<char>>a;
vector<vector<int>>pre;
int sum(int x,int y,int u,int v) {
return pre[u][v] - pre[x - 1][v] - pre[u][y - 1] + pre[x - 1][y - 1];
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n,m,d,k;
cin >> n >> m >> d >> k;
a.assign(n + 5,vector<char>(m + 5));
pre.assign(n + 5,vector<int>(m + 5,0));
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
if (a[i][j] == 'S') pre[i][j]++;
pre[i][j] += pre[i - 1][j] + pre[i][j - 1] - pre[i - 1][j - 1];
}
int ans = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (a[i][j] == 'M' && sum(max(1,i - d),max(1,j - d),min(n,i + d),min(m,j + d)) >= k)
ans++;
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
452 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1628 KB |
Output is correct |
2 |
Correct |
3 ms |
1628 KB |
Output is correct |
3 |
Correct |
4 ms |
1884 KB |
Output is correct |
4 |
Correct |
3 ms |
1628 KB |
Output is correct |
5 |
Correct |
3 ms |
1604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
17008 KB |
Output is correct |
2 |
Correct |
14 ms |
17008 KB |
Output is correct |
3 |
Correct |
15 ms |
17008 KB |
Output is correct |
4 |
Correct |
16 ms |
17004 KB |
Output is correct |
5 |
Correct |
17 ms |
17008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
452 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1628 KB |
Output is correct |
17 |
Correct |
3 ms |
1628 KB |
Output is correct |
18 |
Correct |
4 ms |
1884 KB |
Output is correct |
19 |
Correct |
3 ms |
1628 KB |
Output is correct |
20 |
Correct |
3 ms |
1604 KB |
Output is correct |
21 |
Correct |
18 ms |
17008 KB |
Output is correct |
22 |
Correct |
14 ms |
17008 KB |
Output is correct |
23 |
Correct |
15 ms |
17008 KB |
Output is correct |
24 |
Correct |
16 ms |
17004 KB |
Output is correct |
25 |
Correct |
17 ms |
17008 KB |
Output is correct |
26 |
Correct |
11 ms |
5720 KB |
Output is correct |
27 |
Correct |
9 ms |
3416 KB |
Output is correct |
28 |
Correct |
9 ms |
3676 KB |
Output is correct |
29 |
Correct |
11 ms |
3828 KB |
Output is correct |
30 |
Correct |
10 ms |
4696 KB |
Output is correct |