This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\
\\ //
// 271828___182845__904523__53602__ \\
\\ 87___47____13______52____66__24_ //
// 97___75____72______47____09___36 \\
\\ 999595_____74______96____69___67 //
// 62___77____24______07____66__30_ \\
\\ 35___35____47______59____45713__ //
// \\
\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//
*/
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <climits>
#include <algorithm>
#include <random>
#include <queue>
#include <deque>
#include <iomanip>
#include <string>
#include <tuple>
#include <bitset>
#include <chrono>
#include <ctime>
#include <fstream>
#include <stack>
#include <cstdio>
using namespace std;
using ll = long long;
const int N = 3e5 + 5;
const ll mod = 1e9 + 7, inf = 1e18;
void solve() {
int n, m; cin >> n >> m;
vector<string> v(n);
for (int i = 0; i < n; ++i) cin >> v[i];
vector<vector<int>> van(n);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (v[i][j] == '#') van[i].push_back(j);
}
}
vector<vector<bool>> v1_l(n, vector<bool>(m)), v1_r(n, vector<bool>(m));
vector<vector<bool>> v2_l(n, vector<bool>(m)), v2_r(n, vector<bool>(m));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < van[i].size(); ++j) {
//v1_l[i][van[i][j]] = v1_r[i][van[i][j]] = 1;
if (j + 1 == van[i].size()) continue;
int l = van[i][j], r = van[i][j + 1];
if (!i) continue;
if (v1_l[i - 1][l + 1] && v1_r[i - 1][r - 1]) {
v1_l[i][l] = 1;
v1_r[i][r] = 1;
}
else if (r == l + 2) {
if (v[i - 1][l + 1] == '#') {
v1_l[i][l] = 1;
v1_r[i][r] = 1;
}
}
}
}
for (int i = n - 1; i >= 0; --i) {
for (int j = 0; j < van[i].size(); ++j) {
//v2_l[i][van[i][j]] = v2_r[i][van[i][j]] = 1;
if (j + 1 == van[i].size()) continue;
if (i == n - 1) continue;
int l = van[i][j], r = van[i][j + 1];
if (v2_l[i + 1][l + 1] && v2_r[i + 1][r - 1]) {
v2_l[i][l] = 1;
v2_r[i][r] = 1;
}
else if (l + 2 == r) {
if (v[i + 1][l + 1] == '#') {
v2_l[i][l] = 1;
v2_r[i][r] = 1;
}
}
}
}
int ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j + 1 < van[i].size(); ++j) {
if (v2_l[i][van[i][j]] && v2_r[i][van[i][j + 1]] && v1_l[i][van[i][j]] && v1_r[i][van[i][j + 1]]) {
++ans;
}
}
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
//int t; cin >> t;
//while (t--)
solve();
}
Compilation message (stderr)
Main.cpp: In function 'void solve()':
Main.cpp:54:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for (int j = 0; j < van[i].size(); ++j) {
| ~~^~~~~~~~~~~~~~~
Main.cpp:56:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | if (j + 1 == van[i].size()) continue;
| ~~~~~~^~~~~~~~~~~~~~~~
Main.cpp:72:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for (int j = 0; j < van[i].size(); ++j) {
| ~~^~~~~~~~~~~~~~~
Main.cpp:74:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | if (j + 1 == van[i].size()) continue;
| ~~~~~~^~~~~~~~~~~~~~~~
Main.cpp:91:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | for (int j = 0; j + 1 < van[i].size(); ++j) {
| ~~~~~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |