// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define no1 cout<<"-1\n"
using namespace std;
const int N = 2e5+10;
const int M = 2e5+100;
const int INF = 1e18;
const int mod = 998244353;
// int binpow (int a, int n) {
// if (n == 0)
// return 1;
// if (n % 2 == 1)
// return (binpow (a, n-1) * a)%mod;
// else {
// int b = binpow (a, n/2) % mod;
// return (b * b)%mod;
// }
// }
int n,m,d,k;
void solve(){
cin>>n>>m>>d>>k;
char a[n+1][m+1];
int b[n+1][m+1];
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
b[i][j] = 0;
}
}
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
cin>>a[i][j];
if(a[i][j] == 'S'){
int x1 = max(1ll,i-d);
int y1 = max(1ll,j-d);
int x2 = min(n,i+d);
int y2 = min(m,j+d);
b[x1][y1]++;
if(x2 + 1 <= n){
b[x2 + 1][y1]--;
}
if(y2 + 1 <= m){
b[x1][y2 + 1]--;
}
if(x2 + 1 <= n && y2 + 1 <= m){
b[x2 + 1][y2 + 1]++;
}
}
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(i > 1){
b[i][j] += b[i - 1][j];
}
if(j > 1){
b[i][j] += b[i][j - 1];
}
if(i > 1 && j > 1){
b[i][j] -= b[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' && b[i][j]>=k) ans++;
}
}
cout<<ans<<'\n';
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
// cout.tie(nullptr);
int t = 1;
// cin>>t;
// cout<<"";
for(int i = 1;i<=t;i++){
solve();
// cout<<'\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 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 |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2136 KB |
Output is correct |
2 |
Correct |
4 ms |
2140 KB |
Output is correct |
3 |
Correct |
4 ms |
2652 KB |
Output is correct |
4 |
Correct |
4 ms |
2140 KB |
Output is correct |
5 |
Correct |
4 ms |
2140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
9052 KB |
Output is correct |
2 |
Correct |
11 ms |
9048 KB |
Output is correct |
3 |
Correct |
12 ms |
9048 KB |
Output is correct |
4 |
Correct |
13 ms |
9260 KB |
Output is correct |
5 |
Correct |
12 ms |
9252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 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 |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
2136 KB |
Output is correct |
17 |
Correct |
4 ms |
2140 KB |
Output is correct |
18 |
Correct |
4 ms |
2652 KB |
Output is correct |
19 |
Correct |
4 ms |
2140 KB |
Output is correct |
20 |
Correct |
4 ms |
2140 KB |
Output is correct |
21 |
Correct |
12 ms |
9052 KB |
Output is correct |
22 |
Correct |
11 ms |
9048 KB |
Output is correct |
23 |
Correct |
12 ms |
9048 KB |
Output is correct |
24 |
Correct |
13 ms |
9260 KB |
Output is correct |
25 |
Correct |
12 ms |
9252 KB |
Output is correct |
26 |
Correct |
10 ms |
4700 KB |
Output is correct |
27 |
Correct |
10 ms |
5212 KB |
Output is correct |
28 |
Correct |
11 ms |
5212 KB |
Output is correct |
29 |
Correct |
11 ms |
5212 KB |
Output is correct |
30 |
Correct |
11 ms |
5208 KB |
Output is correct |