/*
Does he have IGM on CF?
-neko_nyaa
*/
#include <bits/stdc++.h>
using namespace std;
//define
#define PB push_back
#define MP make_pair
#define pi acos(-1)
#define int long long
//constant
const int mod=1e9+7;
const long long MOD=998244353LL;
const long long inf=(long long)1e18;
//typedef
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef set<int> SI;
typedef priority_queue<int> pqi;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen("haybales.in", "r", stdin);
//freopen("haybales.out", "w", stdout);
int r,c,d,k;
cin >> r >> c >> d >> k;
char s[r+1][c+1];
for(int i=1;i<=r;i++)
{
for(int j=1;j<=c;j++)
cin >> s[i][j];
}
/*for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
cout << s[i][j];
cout << '\n';
}*/
int pref[r+1][c+1];
memset(pref,0,sizeof(pref));
vector<pii> loc;
for(int i=1;i<=r;i++)
{
for(int j=1;j<=c;j++)
{
if(s[i][j]=='M')
{
loc.push_back({i,j});
}
pref[i][j]=pref[i-1][j]+pref[i][j-1]-pref[i-1][j-1]+(s[i][j]=='S');
}
}
int ans=0;
//cout << loc.size() << '\n';
for(auto &[i,j]:loc)
{
int minx=max(1LL,i-d);
int maxx=min(r,i+d);
int miny=max(1LL,j-d);
int maxy=min(c,j+d);
int total=pref[maxx][maxy]-pref[maxx][miny-1]-pref[minx-1][maxy]+pref[minx-1][miny-1];
ans+=(total>=k);
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2004 KB |
Output is correct |
2 |
Correct |
6 ms |
2132 KB |
Output is correct |
3 |
Correct |
6 ms |
2516 KB |
Output is correct |
4 |
Correct |
4 ms |
2048 KB |
Output is correct |
5 |
Correct |
4 ms |
2132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
13320 KB |
Output is correct |
2 |
Correct |
25 ms |
17480 KB |
Output is correct |
3 |
Correct |
23 ms |
17480 KB |
Output is correct |
4 |
Correct |
17 ms |
13388 KB |
Output is correct |
5 |
Correct |
31 ms |
17344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
5 ms |
2004 KB |
Output is correct |
17 |
Correct |
6 ms |
2132 KB |
Output is correct |
18 |
Correct |
6 ms |
2516 KB |
Output is correct |
19 |
Correct |
4 ms |
2048 KB |
Output is correct |
20 |
Correct |
4 ms |
2132 KB |
Output is correct |
21 |
Correct |
17 ms |
13320 KB |
Output is correct |
22 |
Correct |
25 ms |
17480 KB |
Output is correct |
23 |
Correct |
23 ms |
17480 KB |
Output is correct |
24 |
Correct |
17 ms |
13388 KB |
Output is correct |
25 |
Correct |
31 ms |
17344 KB |
Output is correct |
26 |
Correct |
14 ms |
6908 KB |
Output is correct |
27 |
Correct |
16 ms |
8988 KB |
Output is correct |
28 |
Correct |
14 ms |
6864 KB |
Output is correct |
29 |
Correct |
13 ms |
6864 KB |
Output is correct |
30 |
Correct |
15 ms |
8908 KB |
Output is correct |