#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,m,d,k;
int32_t main(){
CODE_START
cin>>n>>m>>d>>k;
ll sum[n+5][m+5];
char a[n+5][m+5];
for(ll i=0;i<=n;i++)
{
for(ll j=0;j<=m;j++)
{
sum[i][j]=0;
}
}
for(ll i=1;i<=n;i++)
{
for(ll j=1;j<=m;j++)
{
cin>>a[i][j];
if(a[i][j]=='S'){
ll x,y,xx,yy;
x=max(1ll,i-d);
y=max(1ll,j-d);
xx=min(1+n,1+i+d);
yy=min(1+m,1+j+d);
sum[x][y]++;
sum[x][yy]--;
sum[xx][y]--;
sum[xx][yy]++;
}
}
}
for(ll i=1;i<=n;i++){
for(ll j=1;j<=m;j++){
sum[i][j]+=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
}
}
ll ans=0;
for(ll i=1;i<=n;i++)
{
for(ll j=1;j<=m;j++)
{
if(k<=sum[i][j]&a[i][j]=='M'){
// cout<<i<<' '<<j<<' '<<sum[i][j]<<endl;
ans++;
}
}
}
rc(ans);
}
Compilation message
mushrooms.cpp: In function 'int32_t main()':
mushrooms.cpp:62:13: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
62 | if(k<=sum[i][j]&a[i][j]=='M'){
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2156 KB |
Output is correct |
2 |
Correct |
6 ms |
2412 KB |
Output is correct |
3 |
Correct |
6 ms |
2816 KB |
Output is correct |
4 |
Correct |
5 ms |
2432 KB |
Output is correct |
5 |
Correct |
5 ms |
2540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
12288 KB |
Output is correct |
2 |
Correct |
16 ms |
11756 KB |
Output is correct |
3 |
Correct |
19 ms |
11244 KB |
Output is correct |
4 |
Correct |
20 ms |
13036 KB |
Output is correct |
5 |
Correct |
18 ms |
12524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
2156 KB |
Output is correct |
17 |
Correct |
6 ms |
2412 KB |
Output is correct |
18 |
Correct |
6 ms |
2816 KB |
Output is correct |
19 |
Correct |
5 ms |
2432 KB |
Output is correct |
20 |
Correct |
5 ms |
2540 KB |
Output is correct |
21 |
Correct |
19 ms |
12288 KB |
Output is correct |
22 |
Correct |
16 ms |
11756 KB |
Output is correct |
23 |
Correct |
19 ms |
11244 KB |
Output is correct |
24 |
Correct |
20 ms |
13036 KB |
Output is correct |
25 |
Correct |
18 ms |
12524 KB |
Output is correct |
26 |
Correct |
15 ms |
6124 KB |
Output is correct |
27 |
Correct |
17 ms |
5228 KB |
Output is correct |
28 |
Correct |
15 ms |
5356 KB |
Output is correct |
29 |
Correct |
16 ms |
5356 KB |
Output is correct |
30 |
Correct |
15 ms |
5868 KB |
Output is correct |