#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mesh !
using namespace std;
const int N = 10 , MOD = 1e9+7 , INF = 1e12;
const double EPS=1e-10, PI=3.141592653589793238462643383279502;
vector<char>cur;
int32_t main()
{
//freopen("abc.in", "r", stdin);
//fast;
/*
brainzeftstorming
- law 3mlt BS momken ya5od n^2 momken ygeeb awel 4 subtasks momkeeen
- el fekra bta3et cses lma kona bn3ml +1 w -1 w n3ml pref sum b3dha -
- momken n3mel 2d pref sum 3la kol 'S' n3lem el square el heya hta5do b enna n3mel enter b 1 w exit b -1
- tab ma n3mel 2d pref sum bas 3la 'S' 3shan n3raf fe kam 'S' fe el range lol
*/
int r , c , d , k;
cin >> r >> c >> d >> k ;
char grid[r+1][c+1] ; int pref[r+2][c+2];
for(int i = 0 ; i <= r+1 ; i ++) for(int j = 0 ; j <= c+1 ; j ++) pref[i][j]=0;
for(int i = 1 ; i <= r ; i ++)
for(int j = 1 ; j <= c ; j ++)
{
cin >> grid[i][j];
if(grid[i][j]=='S') pref[i][j]++;
}
//n3mel 2d prefsum 3shan nzbat el ranges
for(int i = 1 ; i <= r+1 ; i ++)
{
for(int j = 1 ; j <= c+1 ; j ++)
{
pref[i][j] = pref[i][j] + pref[i-1][j] + pref[i][j-1] - pref[i-1][j-1];
}
}
//m7tagen n3raf l kol 'M' el square range el heya feeh fe kam S
int ans=0;
for(int i = 1 ; i <= r ; i ++)
{
for(int j = 1 ; j <= c ; j ++)
{
if(grid[i][j]!='M') continue;
int top = max(1ll , i-d);
int left = max(1ll , j-d);
int right = min(c , j+d);
int bottom = min(r , i+d);
int cur = pref[bottom][right] - pref[top-1][right] - pref[bottom][left-1] + pref[top-1][left-1];
ans+=(cur>=k);
}
}
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
304 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 |
212 KB |
Output is correct |
10 |
Correct |
1 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 |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
2132 KB |
Output is correct |
2 |
Correct |
14 ms |
2296 KB |
Output is correct |
3 |
Correct |
18 ms |
2748 KB |
Output is correct |
4 |
Correct |
14 ms |
2260 KB |
Output is correct |
5 |
Correct |
15 ms |
2360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
13480 KB |
Output is correct |
2 |
Correct |
40 ms |
13372 KB |
Output is correct |
3 |
Correct |
39 ms |
13448 KB |
Output is correct |
4 |
Correct |
40 ms |
13496 KB |
Output is correct |
5 |
Correct |
44 ms |
13484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
304 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 |
212 KB |
Output is correct |
10 |
Correct |
1 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 |
2 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 |
14 ms |
2132 KB |
Output is correct |
17 |
Correct |
14 ms |
2296 KB |
Output is correct |
18 |
Correct |
18 ms |
2748 KB |
Output is correct |
19 |
Correct |
14 ms |
2260 KB |
Output is correct |
20 |
Correct |
15 ms |
2360 KB |
Output is correct |
21 |
Correct |
42 ms |
13480 KB |
Output is correct |
22 |
Correct |
40 ms |
13372 KB |
Output is correct |
23 |
Correct |
39 ms |
13448 KB |
Output is correct |
24 |
Correct |
40 ms |
13496 KB |
Output is correct |
25 |
Correct |
44 ms |
13484 KB |
Output is correct |
26 |
Correct |
36 ms |
5332 KB |
Output is correct |
27 |
Correct |
34 ms |
5096 KB |
Output is correct |
28 |
Correct |
32 ms |
5204 KB |
Output is correct |
29 |
Correct |
33 ms |
5324 KB |
Output is correct |
30 |
Correct |
36 ms |
5324 KB |
Output is correct |