//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
vector<vector<int>> f, s;
int r, c, d, k;
void add(int x, int y) {
int x1 = max(1, x - d);
int y1 = max(1, y - d);
int x2 = x + d + 1;
int y2 = y + d + 1;
f[x1][y1]++;
if (y2 <= c) {
f[x1][y2]--;
}
if (x2 <= r) {
f[x2][y1]--;
}
if (x2 <= r && y2 <= c) {
f[x2][y2]++;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> r >> c >> d >> k;
vector<vector<char>> field(r + 1, vector<char>(c + 1));
f.assign(r + 1, vector<int>(c + 1, 0));
s.assign(r + 1, vector<int>(c + 1, 0));
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
cin >> field[i][j];
if (field[i][j] == 'S') {
add(i, j);
}
}
}
int ans = 0;
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + f[i][j];
if (field[i][j] == 'M' && s[i][j] >= k) {
ans++;
}
}
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2296 KB |
Output is correct |
2 |
Correct |
8 ms |
2320 KB |
Output is correct |
3 |
Correct |
9 ms |
2808 KB |
Output is correct |
4 |
Correct |
8 ms |
2424 KB |
Output is correct |
5 |
Correct |
8 ms |
2552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
11620 KB |
Output is correct |
2 |
Correct |
26 ms |
11624 KB |
Output is correct |
3 |
Correct |
26 ms |
11624 KB |
Output is correct |
4 |
Correct |
27 ms |
11108 KB |
Output is correct |
5 |
Correct |
25 ms |
11596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
7 ms |
2296 KB |
Output is correct |
17 |
Correct |
8 ms |
2320 KB |
Output is correct |
18 |
Correct |
9 ms |
2808 KB |
Output is correct |
19 |
Correct |
8 ms |
2424 KB |
Output is correct |
20 |
Correct |
8 ms |
2552 KB |
Output is correct |
21 |
Correct |
29 ms |
11620 KB |
Output is correct |
22 |
Correct |
26 ms |
11624 KB |
Output is correct |
23 |
Correct |
26 ms |
11624 KB |
Output is correct |
24 |
Correct |
27 ms |
11108 KB |
Output is correct |
25 |
Correct |
25 ms |
11596 KB |
Output is correct |
26 |
Correct |
26 ms |
7800 KB |
Output is correct |
27 |
Correct |
17 ms |
5240 KB |
Output is correct |
28 |
Correct |
19 ms |
5256 KB |
Output is correct |
29 |
Correct |
22 ms |
5368 KB |
Output is correct |
30 |
Correct |
26 ms |
7160 KB |
Output is correct |