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 <bits/stdc++.h>
using namespace std;
void testCase() {
int n, m;
cin >> n >> m;
vector<string> a(n + 1);
vector<vector<int>> sum(n + 1, vector<int>(m + 1));
for (int i = 1; i <= n; ++i) {
a[i].resize(m);
cin >> a[i];
a[i] = '$' + a[i];
for (int j = 1; j <= m; ++j) {
sum[i][j] = sum[i][j - 1] + (a[i][j] == '#');
}
}
auto checkDown = [&](int lin, int l, int r) -> bool {
while (l <= r) {
if (a[lin][l] != '#' || a[lin][r] != '#' || (l < r && sum[lin][r - 1] - sum[lin][l])) {
return false;
}
lin += 1;
l += 1;
r -= 1;
}
return true;
};
int ans = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (a[i][j] == '#') {
int lin = i + 1, l = j - 1, r = j + 1;
while (lin + (lin - i) <= n && l > 0 && r <= m) {
if (a[lin][l] != '#' || a[lin][r] != '#' || sum[lin][r - 1] - sum[lin][l]) {
break;
}
ans += checkDown(lin + 1, l + 1, r - 1);
lin += 1;
l -= 1;
r += 1;
}
}
}
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int tests = 1;
for (int tc = 0; tc < tests; ++tc) {
testCase();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |