#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
void solve(){
ll a,b,d,k;
cin>>a>>b>>d>>k;
char c[a+1][b+1];
ll pr[a+1][b+1];
for(ll i=1;i<=a;i++){
for(ll j=1;j<=b;j++){
cin>>c[i][j];
pr[i][j]=(c[i][j]=='S')+pr[i-1][j]+pr[i][j-1]-pr[i-1][j-1];
}
}
ll ans=0;
for(ll i=1;i<=a;i++){
for(ll j=1;j<=b;j++){
if(c[i][j]=='M'){
ll l1=0,r1=0,l2=0,r2=0;
l1=max(1ll,i-d);
r1=max(1ll,j-d);
l2=min(a,i+d);
r2=min(b,j+d);
ll count=pr[l2][r2]-pr[l2][r1-1]-pr[l1-1][r2]+pr[l1-1][r1-1];
if(count>=k){
ans++;
}
}
}
}
cout<<ans;
}
int main()
{
ios_base::sync_with_stdio(0),cin.tie(0);
ll t=1,i=1;
//cin>>t;
while(t--){
//cout<<"Case ";
//cout<<i<<':'<<"\n";
//i++;
solve();
}
return 0;
}
Compilation message
mushrooms.cpp: In function 'int main()':
mushrooms.cpp:39:12: warning: unused variable 'i' [-Wunused-variable]
39 | ll t=1,i=1;
| ^
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
404 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
396 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2136 KB |
Output is correct |
2 |
Correct |
3 ms |
2140 KB |
Output is correct |
3 |
Correct |
4 ms |
2652 KB |
Output is correct |
4 |
Correct |
3 ms |
2140 KB |
Output is correct |
5 |
Correct |
4 ms |
2140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
9052 KB |
Output is correct |
2 |
Correct |
11 ms |
9084 KB |
Output is correct |
3 |
Correct |
12 ms |
9252 KB |
Output is correct |
4 |
Correct |
12 ms |
9052 KB |
Output is correct |
5 |
Correct |
11 ms |
9052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
404 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
396 KB |
Output is correct |
13 |
Correct |
0 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 |
2136 KB |
Output is correct |
17 |
Correct |
3 ms |
2140 KB |
Output is correct |
18 |
Correct |
4 ms |
2652 KB |
Output is correct |
19 |
Correct |
3 ms |
2140 KB |
Output is correct |
20 |
Correct |
4 ms |
2140 KB |
Output is correct |
21 |
Correct |
11 ms |
9052 KB |
Output is correct |
22 |
Correct |
11 ms |
9084 KB |
Output is correct |
23 |
Correct |
12 ms |
9252 KB |
Output is correct |
24 |
Correct |
12 ms |
9052 KB |
Output is correct |
25 |
Correct |
11 ms |
9052 KB |
Output is correct |
26 |
Correct |
9 ms |
4700 KB |
Output is correct |
27 |
Correct |
10 ms |
4872 KB |
Output is correct |
28 |
Correct |
9 ms |
4696 KB |
Output is correct |
29 |
Correct |
10 ms |
4700 KB |
Output is correct |
30 |
Correct |
9 ms |
4696 KB |
Output is correct |