#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
#define FOR(i, a, b) for (int i = a; i < (int) b; i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = a; i >= (int) b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)
#define f first
#define s second
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int ms[] = {+31, +29, +31, 30, +31, +30, +31, +31, +30, +31, +30, +31};
vvi dp;
vector< vector<char> > g;
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
int r, c, d, k;
cin >> r >> c >> d >> k;
g.resize(r + 10);
dp.resize(r + 10);
F0R (i, r + 1) {
g[i].resize(c + 10);
dp[i].resize(c + 10);
}
FOR (i, 1, r + 1) {
FOR (j, 1, c + 1) {
cin >> g[i][j];
}
}
dp[1][1] = (g[1][1] == 'S');
FOR (i, 2, r + 1) {
dp[i][1] = dp[i - 1][1] + (g[i][1] == 'S');
}
FOR (i, 2, c + 1) {
dp[1][i] = dp[1][i - 1] + (g[1][i] == 'S');
}
FOR (i, 2, r + 1) {
FOR (j, 2, c + 1) {
dp[i][j] += dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + (g[i][j] == 'S');
}
}
int tot = 0;
FOR (i, 1, r + 1) {
FOR (j, 1, c + 1) {
if (g[i][j] == 'M') {
int linha = min (r, i + d);
int coluna = min (c, j + d);
int cnt = dp[linha][coluna] - (i - d - 1 >= 0 ? dp[i - d - 1][coluna] : 0) - (j - d - 1 >= 0 ? dp[linha][j - d - 1] : 0) + (i - d - 1 >= 0 && j - d - 1 >= 0 ? dp[i - d - 1][j - d - 1] : 0);
tot += (cnt >= k);
}
}
}
cout << tot << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
248 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
296 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
248 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
296 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
380 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1532 KB |
Output is correct |
2 |
Correct |
10 ms |
1656 KB |
Output is correct |
3 |
Correct |
11 ms |
1912 KB |
Output is correct |
4 |
Correct |
9 ms |
1528 KB |
Output is correct |
5 |
Correct |
10 ms |
1656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
5752 KB |
Output is correct |
2 |
Correct |
18 ms |
5752 KB |
Output is correct |
3 |
Correct |
20 ms |
5756 KB |
Output is correct |
4 |
Correct |
18 ms |
5752 KB |
Output is correct |
5 |
Correct |
18 ms |
5752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
248 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
296 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
380 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
9 ms |
1532 KB |
Output is correct |
17 |
Correct |
10 ms |
1656 KB |
Output is correct |
18 |
Correct |
11 ms |
1912 KB |
Output is correct |
19 |
Correct |
9 ms |
1528 KB |
Output is correct |
20 |
Correct |
10 ms |
1656 KB |
Output is correct |
21 |
Correct |
18 ms |
5752 KB |
Output is correct |
22 |
Correct |
18 ms |
5752 KB |
Output is correct |
23 |
Correct |
20 ms |
5756 KB |
Output is correct |
24 |
Correct |
18 ms |
5752 KB |
Output is correct |
25 |
Correct |
18 ms |
5752 KB |
Output is correct |
26 |
Correct |
20 ms |
6136 KB |
Output is correct |
27 |
Correct |
18 ms |
3320 KB |
Output is correct |
28 |
Correct |
17 ms |
3320 KB |
Output is correct |
29 |
Correct |
16 ms |
3320 KB |
Output is correct |
30 |
Correct |
19 ms |
5240 KB |
Output is correct |