#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
///freopen("aaaaa", "r", stdin);
///freopen("bbbbb", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, d, k;
cin >> n >> m >> d >> k;
vector<vector<int>>v(n + 7);
vector<vector<int>>a(n + 7);
for(int i = 0; i < n + 7; i++)
{
v[i].resize(m + 7, 0);
a[i].resize(m + 7, 0);
}
for(int i = 1; i <= n; i++)
{
string s;
cin >> s;
for(int j = 1; j <= m; j++)
{
if(s[j - 1] == '.') v[i][j] = 0;
if(s[j - 1] == 'M') v[i][j] = 1;
if(s[j - 1] == 'S') v[i][j] = 2;
}
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
if(v[i][j] == 2)
{
int rmi = i - d;
int rma = i + d;
int cmi = j - d;
int cma = j + d;
if(rmi < 1) rmi = 1;
if(cmi < 1) cmi = 1;
if(rma > n + 1) rma = n + 1;
if(cma > m + 1) cma = m + 1;
a[rmi][cmi]++;
a[rmi][cma + 1]--;
a[rma + 1][cmi]--;
a[rma + 1][cma + 1]++;
}
}
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
a[i][j] += a[i][j - 1];
}
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
a[i][j] += a[i - 1][j];
}
}
int r = 0;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
if(v[i][j] == 1 && a[i][j] >= k)
{
r++;
}
}
}
cout << r << "\n";
return 0;
}
/**
**/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
512 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1920 KB |
Output is correct |
2 |
Correct |
7 ms |
2048 KB |
Output is correct |
3 |
Correct |
8 ms |
2688 KB |
Output is correct |
4 |
Correct |
7 ms |
2176 KB |
Output is correct |
5 |
Correct |
8 ms |
2432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
32268 KB |
Output is correct |
2 |
Correct |
39 ms |
32908 KB |
Output is correct |
3 |
Correct |
45 ms |
32780 KB |
Output is correct |
4 |
Correct |
42 ms |
32908 KB |
Output is correct |
5 |
Correct |
38 ms |
32868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
512 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
1920 KB |
Output is correct |
17 |
Correct |
7 ms |
2048 KB |
Output is correct |
18 |
Correct |
8 ms |
2688 KB |
Output is correct |
19 |
Correct |
7 ms |
2176 KB |
Output is correct |
20 |
Correct |
8 ms |
2432 KB |
Output is correct |
21 |
Correct |
41 ms |
32268 KB |
Output is correct |
22 |
Correct |
39 ms |
32908 KB |
Output is correct |
23 |
Correct |
45 ms |
32780 KB |
Output is correct |
24 |
Correct |
42 ms |
32908 KB |
Output is correct |
25 |
Correct |
38 ms |
32868 KB |
Output is correct |
26 |
Correct |
31 ms |
8056 KB |
Output is correct |
27 |
Correct |
15 ms |
4864 KB |
Output is correct |
28 |
Correct |
18 ms |
5504 KB |
Output is correct |
29 |
Correct |
14 ms |
5376 KB |
Output is correct |
30 |
Correct |
26 ms |
6528 KB |
Output is correct |