/*
ID: samikgo1
TASK:
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define f first
#define s second
//#define x first
//#define y second
const int INF = INT32_MAX;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("haybales.in","r",stdin);
// freopen("haybales.out","w",stdout);
ll r,c,d,k;
cin >> r >> c >> d >> k;
char grid[r+1][c+1];
vector<vector<ll>> prefix(r+1,vector<ll>(c+1));
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
prefix[i][j] = prefix[i-1][j] + prefix[i][j-1] - prefix[i-1][j-1];
cin>>grid[i][j];
if(grid[i][j]=='S')prefix[i][j]++;
}
}
ll ans = 0;
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
if(grid[i][j]!='M')continue;
ll pre = prefix[min(i+d,r)][min(j+d,c)]+prefix[max(i-d-1,(ll)0)][max(j-d-1,(ll)0)] - prefix[max(i-d-1,(ll)0)][min(j+d,c)] - prefix[min(i+d,r)][max(j-d-1,(ll)0)];
if(pre>=k)ans++;
}
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
260 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
320 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 |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2184 KB |
Output is correct |
2 |
Correct |
5 ms |
2260 KB |
Output is correct |
3 |
Correct |
7 ms |
2788 KB |
Output is correct |
4 |
Correct |
5 ms |
2260 KB |
Output is correct |
5 |
Correct |
7 ms |
2476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
13028 KB |
Output is correct |
2 |
Correct |
16 ms |
13128 KB |
Output is correct |
3 |
Correct |
16 ms |
13012 KB |
Output is correct |
4 |
Correct |
20 ms |
13080 KB |
Output is correct |
5 |
Correct |
22 ms |
13024 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 |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
260 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
320 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 |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
4 ms |
2184 KB |
Output is correct |
17 |
Correct |
5 ms |
2260 KB |
Output is correct |
18 |
Correct |
7 ms |
2788 KB |
Output is correct |
19 |
Correct |
5 ms |
2260 KB |
Output is correct |
20 |
Correct |
7 ms |
2476 KB |
Output is correct |
21 |
Correct |
16 ms |
13028 KB |
Output is correct |
22 |
Correct |
16 ms |
13128 KB |
Output is correct |
23 |
Correct |
16 ms |
13012 KB |
Output is correct |
24 |
Correct |
20 ms |
13080 KB |
Output is correct |
25 |
Correct |
22 ms |
13024 KB |
Output is correct |
26 |
Correct |
16 ms |
5864 KB |
Output is correct |
27 |
Correct |
13 ms |
5204 KB |
Output is correct |
28 |
Correct |
13 ms |
5356 KB |
Output is correct |
29 |
Correct |
13 ms |
5332 KB |
Output is correct |
30 |
Correct |
14 ms |
5876 KB |
Output is correct |