#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(),a.end()
#define pb push_back
#define vt vector
#define endl '\n'
typedef long long ll;
const ll mod=1e9+7;
const ll inf=mod;
const int N=5e5+4;
int n,m,d,r;
void solve(){
cin>>n>>m>>d>>r;
string c[n+10];
int la[n+5][m+5],used[n+5][m+5];
for(int i=0; i<=n+2; ++i) for(int j=0; j<=m+2; ++j) { la[i][j]=0;used[i][j]=0;}
for(int i=1; i<=n; ++i) {
cin>>c[i];
for(int j=1; j<=m; ++j) {
if(c[i][j-1]!='S') continue;
// cout<<i<<' '<<j<<endl;
la[max(i-d,1)][max(j-d,1)]+=1;
la[max(i-d,1)][min(j+d,m+2)+1]-=1;
la[min(i+d,n+2)+1][max(j-d,1)]--;
la[min(i+d,n+2)+1][min(j+d,m+2)+1]++;
}
}
for(int i=1; i<=n; ++i) {
for(int j=1; j<=m; ++j){
used[i][j]=used[i][j-1]+la[i][j];
//cout<<used[i][j]<<' ';
//if(j==m)cout<<endl;
}
for(int j=1; j<=m; ++j) used[i][j]+=used[i-1][j];
}
int z=0;
int mx=0;
for(int i=1; i<=n; ++i) for(int j=1; j<=m; ++j){
if(c[i][j-1]=='M' && used[i][j]>=r) ++mx;
}
cout<<mx<<endl;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int tt=1;
// cin>>tt;
while(tt--) {
solve();
}
}
Compilation message
mushrooms.cpp: In function 'void solve()':
mushrooms.cpp:41:6: warning: unused variable 'z' [-Wunused-variable]
41 | int z=0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 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 |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2140 KB |
Output is correct |
2 |
Correct |
2 ms |
2140 KB |
Output is correct |
3 |
Correct |
3 ms |
2652 KB |
Output is correct |
4 |
Correct |
3 ms |
2328 KB |
Output is correct |
5 |
Correct |
3 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
24548 KB |
Output is correct |
2 |
Correct |
16 ms |
24560 KB |
Output is correct |
3 |
Correct |
16 ms |
24804 KB |
Output is correct |
4 |
Correct |
17 ms |
24804 KB |
Output is correct |
5 |
Correct |
16 ms |
24552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
2140 KB |
Output is correct |
17 |
Correct |
2 ms |
2140 KB |
Output is correct |
18 |
Correct |
3 ms |
2652 KB |
Output is correct |
19 |
Correct |
3 ms |
2328 KB |
Output is correct |
20 |
Correct |
3 ms |
2396 KB |
Output is correct |
21 |
Correct |
17 ms |
24548 KB |
Output is correct |
22 |
Correct |
16 ms |
24560 KB |
Output is correct |
23 |
Correct |
16 ms |
24804 KB |
Output is correct |
24 |
Correct |
17 ms |
24804 KB |
Output is correct |
25 |
Correct |
16 ms |
24552 KB |
Output is correct |
26 |
Correct |
9 ms |
7000 KB |
Output is correct |
27 |
Correct |
6 ms |
4956 KB |
Output is correct |
28 |
Correct |
7 ms |
5468 KB |
Output is correct |
29 |
Correct |
7 ms |
5212 KB |
Output is correct |
30 |
Correct |
8 ms |
5980 KB |
Output is correct |