#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define N 100005
int n,m,d,k,ans;
vector<vector<int>> fen;
void upd(int x,int y,int k){
x=max(x,1),y=max(y,1);
for(int i=x;i<=n;i+=i&-i)for(int j=y;j<=m;j+=j&-j)fen[i][j]+=k;
}
void upd_rec(int x,int y){
upd(x-d,y-d,1);
upd(x-d,y+d+1,-1);
upd(x+d+1,y-d,-1);
upd(x+d+1,y+d+1,1);
}
int query(int x,int y){
x=min(x,n),y=min(y,m);
int ans=0;
for(int i=x;i>0;i-=i&-i)for(int j=y;j>0;j-=j&-j)ans+=fen[i][j];
return ans;
}
int main(){
int i,j;
scanf("%d %d %d %d",&n,&m,&d,&k);
char s[n+5][m+5];
for(i=1;i<=n;i++)scanf(" %s",s[i]+1);
fen.resize(n+5);
for(i=0;i<n+5;i++)fen[i].resize(m+5);
for(i=1;i<=n;i++)for(j=1;j<=m;j++)if(s[i][j]=='S')upd_rec(i,j);
for(i=1;i<=n;i++)for(j=1;j<=m;j++)if(s[i][j]=='M'&&query(i,j)>=k)ans++;
printf("%d",ans);
return 0;
}
Compilation message
mushrooms.cpp: In function 'int main()':
mushrooms.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | scanf("%d %d %d %d",&n,&m,&d,&k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
mushrooms.cpp:33:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | for(i=1;i<=n;i++)scanf(" %s",s[i]+1);
| ~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1364 KB |
Output is correct |
2 |
Correct |
2 ms |
1468 KB |
Output is correct |
3 |
Correct |
2 ms |
1748 KB |
Output is correct |
4 |
Correct |
2 ms |
1492 KB |
Output is correct |
5 |
Correct |
2 ms |
1620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
15368 KB |
Output is correct |
2 |
Correct |
14 ms |
15444 KB |
Output is correct |
3 |
Correct |
15 ms |
15444 KB |
Output is correct |
4 |
Correct |
22 ms |
15388 KB |
Output is correct |
5 |
Correct |
17 ms |
15444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
300 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
1364 KB |
Output is correct |
17 |
Correct |
2 ms |
1468 KB |
Output is correct |
18 |
Correct |
2 ms |
1748 KB |
Output is correct |
19 |
Correct |
2 ms |
1492 KB |
Output is correct |
20 |
Correct |
2 ms |
1620 KB |
Output is correct |
21 |
Correct |
14 ms |
15368 KB |
Output is correct |
22 |
Correct |
14 ms |
15444 KB |
Output is correct |
23 |
Correct |
15 ms |
15444 KB |
Output is correct |
24 |
Correct |
22 ms |
15388 KB |
Output is correct |
25 |
Correct |
17 ms |
15444 KB |
Output is correct |
26 |
Correct |
19 ms |
4452 KB |
Output is correct |
27 |
Correct |
15 ms |
3204 KB |
Output is correct |
28 |
Correct |
29 ms |
3540 KB |
Output is correct |
29 |
Correct |
17 ms |
3372 KB |
Output is correct |
30 |
Correct |
15 ms |
4192 KB |
Output is correct |