#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll,ll>
ll r,c,d,w;
const int N = 5e5+1;
vector<pii> mush;
int main()
{
cin >> r >> c >> d >> w;
char b[r+1][c+1];
ll qs[r+1][c+1];
for(int i=1;i<=r;++i)
{
for(int j=1;j<=c;++j)
{
qs[i][j] = 0;
cin >> b[i][j];
if(b[i][j] == 'S') qs[i][j] = 1;
if(b[i][j] == 'M') mush.push_back({i,j});
}
}
for(int i=1;i<=r;++i)
{
for(int j=1;j<=c;++j)
{
qs[i][j] += qs[i-1][j]+qs[i][j-1]-qs[i-1][j-1];
}
}
ll cnt = 0;
for(pii xy : mush)
{
ll x,y;
tie(x,y) = xy;
ll mx = min(r,x+d),mnx = max((ll)1,x-d);
ll my = min(c,y+d),mny = max((ll)1,y-d);
ll spring = qs[mx][my]-qs[mx][mny-1]-qs[mnx-1][my]+qs[mnx-1][mny-1];
if(spring >= w) ++cnt;
}
cout << cnt;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 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 |
360 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
2048 KB |
Output is correct |
2 |
Correct |
13 ms |
2096 KB |
Output is correct |
3 |
Correct |
17 ms |
2388 KB |
Output is correct |
4 |
Correct |
13 ms |
2004 KB |
Output is correct |
5 |
Correct |
15 ms |
2224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
13236 KB |
Output is correct |
2 |
Correct |
43 ms |
17400 KB |
Output is correct |
3 |
Correct |
44 ms |
17440 KB |
Output is correct |
4 |
Correct |
38 ms |
13264 KB |
Output is correct |
5 |
Correct |
49 ms |
17412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 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 |
360 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
13 ms |
2048 KB |
Output is correct |
17 |
Correct |
13 ms |
2096 KB |
Output is correct |
18 |
Correct |
17 ms |
2388 KB |
Output is correct |
19 |
Correct |
13 ms |
2004 KB |
Output is correct |
20 |
Correct |
15 ms |
2224 KB |
Output is correct |
21 |
Correct |
38 ms |
13236 KB |
Output is correct |
22 |
Correct |
43 ms |
17400 KB |
Output is correct |
23 |
Correct |
44 ms |
17440 KB |
Output is correct |
24 |
Correct |
38 ms |
13264 KB |
Output is correct |
25 |
Correct |
49 ms |
17412 KB |
Output is correct |
26 |
Correct |
35 ms |
7268 KB |
Output is correct |
27 |
Correct |
38 ms |
9264 KB |
Output is correct |
28 |
Correct |
38 ms |
7240 KB |
Output is correct |
29 |
Correct |
37 ms |
7360 KB |
Output is correct |
30 |
Correct |
36 ms |
9424 KB |
Output is correct |