#include <bits/stdc++.h>
using namespace std;
# define int long long
# define fir first
# define sec second
# define pb push_back
# define endl "\n"
const int cnst = 2e5+5;
bool mutipletestcase = 0;
//bool debug = false;
void solve() {
int n, m, d, s; cin >> n >> m >> d >> s;
char table[n+5][m+5];
int pre[n+5][m+5];
memset(pre, 0, sizeof(pre));
for(int i = 1; i<=n; i++) for(int j = 1; j<=m; j++) {
cin >> table[i][j];
if(table[i][j] == 'S')
pre[max(1ll, i-d)][max(1ll, j-d)]++,
pre[min(n+1, i+d+1)][min(m+1, j+d+1)]++,
pre[max(1ll, i-d)][min(m+1, j+d+1)]--,
pre[min(n+1, i+d+1)][max(1ll, j-d)]--;
}
int ans = 0;
for(int i = 1; i<=n; i++) for(int j = 1; j<=m; j++) {
pre[i][j] += pre[i-1][j] + pre[i][j-1] - pre[i-1][j-1];
cerr << pre[i][j] << " ";
if(j == m) cerr << endl;
if(table[i][j] == 'M' && pre[i][j] >= s) ans++;
}
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int t = 1;
if(mutipletestcase) cin >> t;
while(t--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
16 ms |
568 KB |
Output is correct |
3 |
Correct |
20 ms |
560 KB |
Output is correct |
4 |
Correct |
5 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
16 ms |
568 KB |
Output is correct |
3 |
Correct |
20 ms |
560 KB |
Output is correct |
4 |
Correct |
5 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
404 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
17 ms |
568 KB |
Output is correct |
9 |
Correct |
7 ms |
388 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
348 KB |
Output is correct |
3 |
Correct |
19 ms |
552 KB |
Output is correct |
4 |
Correct |
2 ms |
464 KB |
Output is correct |
5 |
Correct |
11 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
380 ms |
2660 KB |
Output is correct |
2 |
Correct |
405 ms |
2900 KB |
Output is correct |
3 |
Correct |
496 ms |
3412 KB |
Output is correct |
4 |
Correct |
413 ms |
3104 KB |
Output is correct |
5 |
Correct |
434 ms |
2700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
975 ms |
29752 KB |
Output is correct |
2 |
Correct |
954 ms |
28240 KB |
Output is correct |
3 |
Correct |
984 ms |
29800 KB |
Output is correct |
4 |
Correct |
983 ms |
29780 KB |
Output is correct |
5 |
Correct |
972 ms |
29524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
16 ms |
568 KB |
Output is correct |
3 |
Correct |
20 ms |
560 KB |
Output is correct |
4 |
Correct |
5 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
404 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
17 ms |
568 KB |
Output is correct |
9 |
Correct |
7 ms |
388 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
4 ms |
344 KB |
Output is correct |
12 |
Correct |
8 ms |
348 KB |
Output is correct |
13 |
Correct |
19 ms |
552 KB |
Output is correct |
14 |
Correct |
2 ms |
464 KB |
Output is correct |
15 |
Correct |
11 ms |
512 KB |
Output is correct |
16 |
Correct |
380 ms |
2660 KB |
Output is correct |
17 |
Correct |
405 ms |
2900 KB |
Output is correct |
18 |
Correct |
496 ms |
3412 KB |
Output is correct |
19 |
Correct |
413 ms |
3104 KB |
Output is correct |
20 |
Correct |
434 ms |
2700 KB |
Output is correct |
21 |
Correct |
975 ms |
29752 KB |
Output is correct |
22 |
Correct |
954 ms |
28240 KB |
Output is correct |
23 |
Correct |
984 ms |
29800 KB |
Output is correct |
24 |
Correct |
983 ms |
29780 KB |
Output is correct |
25 |
Correct |
972 ms |
29524 KB |
Output is correct |
26 |
Correct |
1010 ms |
8788 KB |
Output is correct |
27 |
Correct |
1002 ms |
7784 KB |
Output is correct |
28 |
Correct |
944 ms |
8816 KB |
Output is correct |
29 |
Correct |
1006 ms |
8216 KB |
Output is correct |
30 |
Correct |
983 ms |
8276 KB |
Output is correct |