#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxR = 5e5+5;
int r, c, d, k;
string garden[maxR];
int main(){
bool watered[maxR][maxR];
memset(watered, false, sizeof(watered));
cin >> r >> c >> d >> k;
for(int i = 0; i<r; i++){
cin >> garden[i];
}
vector<vector<int>> kena;
for(int i = 0; i<r; i++){
vector<int> ps;
for(int j = 0; j<c; j++){
ps.push_back(0);
}
kena.push_back(ps);
}
for(int i = 0; i<r; i++){
for(int j = 0; j<c; j++){
if(garden[i][j]=='S')
{
// atas kiri [i-d][j-d]
// bawah kanan [i+d][j+d]
// atas kanan [i-d][j+d]
// bawah kiri [i+d][j-d]
int atas = max(i-d, 0);
int kiri = max(j-d, 0);
kena[atas][kiri]++;
int kanan = -1, bawah = -1;
if(i+d+1<=r-1) bawah = i+d+1;
if(j+d+1<=c-1) kanan = j+d+1;
if(kanan!=-1) kena[atas][kanan]--;
if(bawah!=-1) kena[bawah][kiri]--;
if(kanan!=-1 && bawah!=-1) kena[kanan][bawah]++;
}
}
}
ll ans = 0;
for(int i = 0; i<r; i++){
for(int j = 0; j<c; j++){
if(i!=0) kena[i][j] += kena[i-1][j];
if(j!=0) kena[i][j] += kena[i][j-1];
if(i!=0 && j!=0) kena[i][j] -= kena[i-1][j-1];
if(garden[i][j]=='M' && kena[i][j] >= k) ans++;
}
// cout << endl;
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
128 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
128 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
127 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
126 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
126 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
128 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |