/*
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\
\\ //
// 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 = 1; i + 1 < n; ++i) {
for (int j = 0; j < m; ++j) {
if (v[i][j] == '#') van[i].push_back(j);
}
}
vector<vector<bool>> uxix_dzax(n, vector<bool>(m)), uxix_aj(n, vector<bool>(m));
for (int i = 1; i < n - 1; ++i) {
for (int j = 0; j + 1 < van[i].size(); ++j) {
int l = van[i][j], r = van[i][j + 1];
if (l % 2 != r % 2) continue;
if (r - l == 2) {
if (v[i - 1][l + 1] == '#') {
uxix_dzax[i][l] = uxix_aj[i][r] = 1;
}
}
else {
if (uxix_dzax[i - 1][l + 1] && uxix_aj[i - 1][r - 1]) {
int id = upper_bound(van[i - 1].begin(), van[i - 1].end(), l + 1) - van[i - 1].begin();
if (van[i - 1][id] != r - 1) continue;
uxix_aj[i][r] = uxix_dzax[i][l] = 1;
}
}
}
}
vector<vector<bool>> tars_dzax(n, vector<bool>(m)), tars_aj(n, vector<bool>(m));
for (int i = n - 2; i >= 1; --i) {
for (int j = 0; j + 1 < van[i].size(); ++j) {
int l = van[i][j], r = van[i][j + 1];
if (l % 2 != r % 2) continue;
if (r - l == 2) {
if (v[i + 1][l + 1] == '#') {
tars_dzax[i][l] = tars_aj[i][r] = 1;
}
}
else {
if (tars_dzax[i + 1][l + 1] && tars_aj[i + 1][r - 1]) {
int id = upper_bound(van[i + 1].begin(), van[i + 1].end(), l + 1) - van[i + 1].begin();
if (van[i + 1][id] != r - 1) continue;
tars_dzax[i][l] = tars_aj[i][r] = 1;
}
}
}
}
int ans = 0;
for (int i = 1; i < n - 1; ++i) {
for (int j = 0; j + 1 < van[i].size(); ++j) {
int l = van[i][j], r = van[i][j + 1];
if (!uxix_dzax[i][l] || !uxix_aj[i][r]) continue;
if (!tars_dzax[i][l] || !tars_aj[i][r]) continue;
// cout << i + 1 << " " << l + 1 << " " << r + 1 << "\n";
++ans;
}
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
//int t; cin >> t;
//while (t--)
solve();
}
Compilation message
Main.cpp: In function 'void solve()':
Main.cpp:53:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int j = 0; j + 1 < van[i].size(); ++j) {
| ~~~~~~^~~~~~~~~~~~~~~
Main.cpp:72:27: 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 + 1 < van[i].size(); ++j) {
| ~~~~~~^~~~~~~~~~~~~~~
Main.cpp:91:27: 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) {
| ~~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
20 ms |
10056 KB |
Output is correct |
15 |
Correct |
40 ms |
25440 KB |
Output is correct |
16 |
Correct |
69 ms |
17216 KB |
Output is correct |
17 |
Correct |
29 ms |
11460 KB |
Output is correct |
18 |
Correct |
65 ms |
26724 KB |
Output is correct |
19 |
Correct |
19 ms |
9264 KB |
Output is correct |
20 |
Correct |
22 ms |
10976 KB |
Output is correct |
21 |
Correct |
19 ms |
9352 KB |
Output is correct |
22 |
Correct |
41 ms |
13588 KB |
Output is correct |
23 |
Correct |
34 ms |
12072 KB |
Output is correct |
24 |
Correct |
41 ms |
13636 KB |
Output is correct |
25 |
Correct |
17 ms |
9084 KB |
Output is correct |
26 |
Correct |
55 ms |
16736 KB |
Output is correct |