#include <bits/stdc++.h>
#define ii pair<int, int>
using namespace std;
vector<vector<int>> v;
int ans = 0;
queue<ii> q;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int N, M, D, K;
cin >> N >> M >> D >> K;
int rd = D * 2 + 1;
for(int i = 0; i < N; i++){
string line;
cin >> line;
vector<int> tmp;
for(int j = 0; j < M; j++){
int qsl = j == 0 ? 0 : tmp[j - 1];
int qsu = i == 0 ? 0 : v[i - 1][j];
int qslu = (i == 0 || j == 0) ? 0 : v[i - 1][j - 1];
tmp.push_back(qsl + qsu - qslu + (line[j] == 'S' ? 1 : 0));
if(line[j] == 'M') q.push({i + D, j + D});
while(!q.empty() && min(q.front().first, N - 1) == i && min(q.front().second, M - 1) == j){
auto [ni, nj] = q.front();
int qsu2 = ni - rd < 0 ? 0 : v[ni - rd][j];
int qsl2 = nj - rd < 0 ? 0 : tmp[nj - rd];
int qslu2 = (ni - rd < 0 || nj - rd < 0) ? 0 : v[ni - rd][nj - rd];
if(tmp[j] - qsl2 - qsu2 + qslu2 >= K) ans++;
// printf(">> %d %d : %d\n", i - rd, j - rd, tmp[j] - qsl2 - qsu2 + qslu2 >= K);
q.pop();
}
}
v.push_back(tmp);
}
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 |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
340 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 |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 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 |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
1236 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
6416 KB |
Output is correct |
2 |
Correct |
9 ms |
5460 KB |
Output is correct |
3 |
Correct |
9 ms |
7260 KB |
Output is correct |
4 |
Correct |
9 ms |
5688 KB |
Output is correct |
5 |
Correct |
9 ms |
7012 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 |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 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 |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |