This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
using namespace std;
vector<vector<long long>> pref;
long long get(int i, int l, int r)
{
return pref[i][r+1] - pref[i][l];
}
int main()
{
int n, m; cin >> n >> m;
vector<string> mat(n);
for (auto& x : mat) cin >> x;
vector<vector<int>> a, b, c, d;
a = b = c = d = vector<vector<int>>(n, vector<int>(m, -1));
pref = vector<vector<long long>>(n, vector<long long>(m + 1));
for (int i = 0; i < n; ++i) {
for (int j = 1; j <= m; ++j) {
pref[i][j] = pref[i][j - 1] + (mat[i][j - 1] == '#');
}
}
//cout << get(2, 1, 6) << '\n';
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (i > 0 && j + 2 < m) {
if (mat[i][j] == '#' && mat[i][j + 1] == '.' && mat[i][j + 2] == '#' && mat[i - 1][j + 1] == '#') a[i][j] = 1, b[i][j + 2] = 1;
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (mat[i][j] != '#') continue;
int x1 = j;
++j;
for (; j < m; ++j) {
if (mat[i][j] == '#') break;
}
//cout << i << ' ' << j << '\n';
if (j == m || i == 0 || x1 + 1 >= m || j==0) continue;
if (a[i - 1][x1 + 1] == 1 && b[i - 1][j - 1] == 1 && get(i-1, x1+1, j-1) == 2) a[i][x1] = 1, b[i][j] = 1;
--j;
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (i + 1 < n && j + 2 < m) {
if (mat[i][j] == '#' && mat[i][j + 1] == '.' && mat[i][j + 2] == '#' && mat[i + 1][j + 1] == '#') c[i][j] = 1, d[i][j + 2] = 1;
}
}
}
for (int i = n-1; i > 0; --i) {
for (int j = 0; j < m; ++j) {
if (mat[i][j] != '#') continue;
int x1 = j;
++j;
for (; j < m; ++j) {
if (mat[i][j] == '#') break;
}
if (j == m || i == n-1 || x1 + 1 >= m || j == 0) continue;
if (c[i + 1][x1 + 1] == 1 && d[i + 1][j - 1] == 1 && get(i+1, x1+1, j-1) == 2) c[i][x1] = 1, d[i][j] = 1;
--j;
}
}
int ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (mat[i][j] != '#') continue;
int x1 = j;
++j;
for (; j < m; ++j) {
if (mat[i][j] == '#') break;
}
if (j == m) continue;
if (a[i][x1] == 1 && b[i][j] == 1 && c[i][x1] == 1 && d[i][j] == 1) ++ans;
--j;
}
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |