#include <bits/stdc++.h>
using namespace std;
#define i128 __int128
#define ll long long
#define ff first
#define ss second
#define pll pair<ll, ll>
#define pb push_back
#define elif else if
#define fast_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const ll MOD = 1e9+7;
const ll base = 1e18;
const ll maxn = 5e5+5;
int main(){
fast_io;
ll r,c,d,k;
cin>>r>>c>>d>>k;
vector<vector<ll>> prefix(r + 5,vector<ll>(c + 5, 0));
vector<vector<char>> a(r + 5, vector<char> (c + 5));
for (int i=0;i<r;i++){
for (int j=0;j<c;j++){
cin>>a[i][j];
//cout<<a[0][i]<<endl;
if (a[i][j]=='S'){
//range
ll startR=max(0LL,i-d);
ll startC=max(0LL,j-d);
ll endR=min(r-1,i+d);
ll endC=min(c-1,j+d);
prefix[startR][startC]+=1;
prefix[startR][endC+1]-=1;
prefix[endR+1][startC]-=1;
prefix[endR+1][endC+1]+=1;
}
}
}
//cout << 0<<endl;
for (int i=0;i<r;i++){
for (int j=0;j<c;j++){
prefix[i][j]=(i == 0 ? 0 : prefix[i-1][j])+(j == 0 ? 0 : prefix[i][j-1])-(i == 0 || j == 0 ? 0 : prefix[i-1][j-1]) +prefix[i][j];
}
}
ll ans=0;
for (int i=0;i<r;i++){
for (int j=0;j<c;j++){
if (a[i][j]=='M'&&prefix[i][j]>=k){
ans++;
}
//cout<<p[i]<<endl;
}
}
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2384 KB |
Output is correct |
2 |
Correct |
5 ms |
2384 KB |
Output is correct |
3 |
Correct |
9 ms |
3064 KB |
Output is correct |
4 |
Correct |
5 ms |
2492 KB |
Output is correct |
5 |
Correct |
5 ms |
2640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
27728 KB |
Output is correct |
2 |
Correct |
27 ms |
27896 KB |
Output is correct |
3 |
Correct |
27 ms |
27728 KB |
Output is correct |
4 |
Correct |
27 ms |
27728 KB |
Output is correct |
5 |
Correct |
26 ms |
27896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
504 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
5 ms |
2384 KB |
Output is correct |
17 |
Correct |
5 ms |
2384 KB |
Output is correct |
18 |
Correct |
9 ms |
3064 KB |
Output is correct |
19 |
Correct |
5 ms |
2492 KB |
Output is correct |
20 |
Correct |
5 ms |
2640 KB |
Output is correct |
21 |
Correct |
31 ms |
27728 KB |
Output is correct |
22 |
Correct |
27 ms |
27896 KB |
Output is correct |
23 |
Correct |
27 ms |
27728 KB |
Output is correct |
24 |
Correct |
27 ms |
27728 KB |
Output is correct |
25 |
Correct |
26 ms |
27896 KB |
Output is correct |
26 |
Correct |
16 ms |
8016 KB |
Output is correct |
27 |
Correct |
15 ms |
5456 KB |
Output is correct |
28 |
Correct |
15 ms |
5712 KB |
Output is correct |
29 |
Correct |
14 ms |
5712 KB |
Output is correct |
30 |
Correct |
13 ms |
6992 KB |
Output is correct |