#include <bits/stdc++.h>
using namespace std;
#define pii pair<ll,ll>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define freeopen freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define mod 1000000000
#define pb push_back
#define mk make_pair
#define ll long long
#define foor(x,vec) for(auto x:vec ){cout<<x<<" ";}
#define fi first
#define se second
#define MAXN 200069
#define lld long double
#define cha ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ffl fflush(stdout)
#define sst string
ll mvx[]={0,0,-1,1};
ll mvy[]={1,-1,0,0};
map<sst,ll> cnt;
ll n,m,s,d;
void solve(){
cin>>n>>m>>d>>s;
char c[n+10][m+10];
ll dp[n+10][m+10];
REP(i,0,n+3){
REP(j,0,m+3)dp[i][j]=0;
}
REP(i,1,n)REP(j,1,m)cin>>c[i][j];
REP(i,1,n){
REP(j,1,m){
if(c[i][j]=='S'){
dp[min(i+d,n)+1][min(j+d,m)+1]++;
dp[max(i-d,(ll)1)][max(j-d,(ll)1)]++;
dp[max(i-d,(ll)1)][min(j+d,m)+1]--;
dp[min(i+d,n)+1][max(j-d,(ll)1)]--;
}
}
}
ll ans=0;
REP(i,1,n){
REP(j,1,m){
dp[i][j]+=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
if(dp[i][j]>=s && c[i][j]=='M')ans++;
}
}
cout<<ans<<endl;
}
int main(){
ll tc;
tc=1;
// cin>>tc;
while(tc--){
solve();
}
}
# |
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 |
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 |
1 ms |
348 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 |
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 |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 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 |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2240 KB |
Output is correct |
2 |
Correct |
7 ms |
2140 KB |
Output is correct |
3 |
Correct |
8 ms |
2652 KB |
Output is correct |
4 |
Correct |
7 ms |
2140 KB |
Output is correct |
5 |
Correct |
7 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
48732 KB |
Output is correct |
2 |
Correct |
49 ms |
48744 KB |
Output is correct |
3 |
Correct |
37 ms |
48732 KB |
Output is correct |
4 |
Correct |
36 ms |
48732 KB |
Output is correct |
5 |
Correct |
40 ms |
48720 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 |
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 |
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 |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 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 |
344 KB |
Output is correct |
16 |
Correct |
7 ms |
2240 KB |
Output is correct |
17 |
Correct |
7 ms |
2140 KB |
Output is correct |
18 |
Correct |
8 ms |
2652 KB |
Output is correct |
19 |
Correct |
7 ms |
2140 KB |
Output is correct |
20 |
Correct |
7 ms |
2396 KB |
Output is correct |
21 |
Correct |
41 ms |
48732 KB |
Output is correct |
22 |
Correct |
49 ms |
48744 KB |
Output is correct |
23 |
Correct |
37 ms |
48732 KB |
Output is correct |
24 |
Correct |
36 ms |
48732 KB |
Output is correct |
25 |
Correct |
40 ms |
48720 KB |
Output is correct |
26 |
Correct |
18 ms |
6748 KB |
Output is correct |
27 |
Correct |
17 ms |
5044 KB |
Output is correct |
28 |
Correct |
19 ms |
5980 KB |
Output is correct |
29 |
Correct |
16 ms |
5720 KB |
Output is correct |
30 |
Correct |
22 ms |
5980 KB |
Output is correct |