#include <bits/stdc++.h>
#define sts(v) stable_sort(v.BE, v.E)
#define Rsts(v) stable_sort(v.rBE, v.rE)
#define rev(v) reverse(v.BE, v.E)
#define BE begin()
#define rBE rbegin()
#define E end()
#define rE rend()
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
using namespace std;
using ll = long long;
const int MAXN = 1e5 + 1;
const int MOD = 1e9 + 7;
int n, m, D, K;
pair<int, int> new_cord(int a, int b){
if(a < 1 or a > n + D or b < 1 or b > m + D)return {0, 0};
else return {a, b};
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m >> D >> K;
vector<pair<int,int>> mushroom;
vector<vector<int>> v(n + D + 1, vector<int> (m + D + 1)), ta(n + D + 1, vector<int> (m + D + 1));
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++){
char c; cin >> c;
if(c == 'S')v[i][j] = 1;
else if(c == 'M')mushroom.pb({i, j});
}
for(int i = 1; i <= n + D; i++)
for(int j = 1; j <= m + D; j++)
ta[i][j] = ta[i - 1][j] + ta[i][j - 1] - ta[i - 1][j - 1] + v[i][j];
int cnt = 0;
for(auto &i : mushroom){
pair<int, int> cor1 = new_cord(i.F + D, i.S + D), cor2 = new_cord(i.F - D - 1, i.S - D - 1),
cor3 = new_cord(i.F + D, i.S - D - 1), cor4 = new_cord(i.F - D - 1, i.S + D);
int mini = min(min(min(cor3.F, cor3.S), min(cor1.F, cor1.S)), min(min(cor4.F, cor4.S), min(cor2.F, cor2.S)));
while(mini < 0){
}
if(K <= ta[cor1.F][cor1.S] + ta[cor2.F][cor2.S] - ta[cor3.F][cor3.S] - ta[cor4.F][cor4.S])cnt++;
}
cout << cnt << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
848 KB |
Output is correct |
4 |
Correct |
1 ms |
592 KB |
Output is correct |
5 |
Correct |
1 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
848 KB |
Output is correct |
4 |
Correct |
1 ms |
592 KB |
Output is correct |
5 |
Correct |
1 ms |
592 KB |
Output is correct |
6 |
Correct |
1 ms |
592 KB |
Output is correct |
7 |
Correct |
1 ms |
592 KB |
Output is correct |
8 |
Correct |
1 ms |
592 KB |
Output is correct |
9 |
Correct |
1 ms |
592 KB |
Output is correct |
10 |
Correct |
1 ms |
336 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 |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5968 KB |
Output is correct |
2 |
Correct |
4 ms |
3920 KB |
Output is correct |
3 |
Correct |
4 ms |
3152 KB |
Output is correct |
4 |
Correct |
6 ms |
5760 KB |
Output is correct |
5 |
Correct |
4 ms |
2812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
110 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
848 KB |
Output is correct |
4 |
Correct |
1 ms |
592 KB |
Output is correct |
5 |
Correct |
1 ms |
592 KB |
Output is correct |
6 |
Correct |
1 ms |
592 KB |
Output is correct |
7 |
Correct |
1 ms |
592 KB |
Output is correct |
8 |
Correct |
1 ms |
592 KB |
Output is correct |
9 |
Correct |
1 ms |
592 KB |
Output is correct |
10 |
Correct |
1 ms |
336 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 |
592 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
592 KB |
Output is correct |
16 |
Correct |
6 ms |
5968 KB |
Output is correct |
17 |
Correct |
4 ms |
3920 KB |
Output is correct |
18 |
Correct |
4 ms |
3152 KB |
Output is correct |
19 |
Correct |
6 ms |
5760 KB |
Output is correct |
20 |
Correct |
4 ms |
2812 KB |
Output is correct |
21 |
Runtime error |
110 ms |
262144 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |