// Krzysztof Małysa #include <bits/stdc++.h> using namespace std; #define FOR(i,a,n) for (auto i = (a), i ## __ = (n); i <= i ## __; ++i) #define FORD(i,a,n) for (auto i = (a), i ## __ = (n); i >= i ## __; --i) #define REP(i,n) FOR(i, 0, n - 1) #define ALL(x) x.begin(), x.end() #define SZ(x) (int(x.size())) #define EB emplace_back #define ST first #define ND second #define tpv typedef vector< typedef long long LL; typedef pair<int, int> PII; tpv int> VI; tpv VI> VVI; tpv PII> VPII; tpv LL> VLL; constexpr char nl = '\n'; #define endl nl #define ris return *this #define tem template<class T tem, class B> inline void mini(T&& a, B&& b) { if (b < a) a = b; } tem, class B> inline void maxi(T&& a, B&& b) { if (b > a) a = b; } int ceil2(int x) { return x < 2 ? 1 : 1 << (sizeof(x) * 8 - __builtin_clz(x - 1)); } tem> struct Dump { T a, b; }; tem> auto dump(T&& x) -> Dump<decltype(x.begin())> { return {ALL(x)}; } struct Debug { ~Debug() { cerr << endl; } tem> auto operator<<(T x) -> decltype(cerr << x, *this) { cerr << boolalpha << x; return *this; } tem> auto operator<<(T x) -> decltype(x.begin(), *this) { auto a = x.begin(), b = x.end(); *this << "{"; for (; a != b;) *this << *a++, *this << (a == b ? "" : " "); return *this << "}"; } tem, class B> Debug& operator<<(pair<T, B> p) { ris << "(" << p.ST << ", " << p.ND << ")"; } tem> Debug& operator<<(Dump<T> d) { *this << "{\n"; for (T a = d.a, c = a; a != d.b; ++a) *this << " " << distance(c, a) << ": " << *a << '\n'; ris << "}"; } }; struct Foo {tem>Foo& operator<<(T) {ris;}}; #ifdef DEBUG # define DEB(x...) x # define deb Debug() #else # define DEB(...) # define deb Foo() #endif #define imie(x...) #x ": " << (x) << " " #define LOG(x...) deb << imie(x) #define DOG(x...) deb << #x ": " << dump(x) << " " int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, kk; cin >> n >> kk; vector<vector<char>> P(n + 2, vector<char>(n + 2, '.')); FOR (i, 1, n) FOR (j, 1, n) cin >> P[i][j]; constexpr int di[] = {-1, 1, 0, 0}; constexpr int dj[] = {0, 0, -1, 1}; int res = 0; FOR (i, 1, n) FOR (j, 1, n) if (P[i][j] == '.') REP (k, 4) if (P[i + di[k]][j + dj[k]] == '#') { ++res; break; } cout << res << nl; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | // Krzysztof Małysa #include <bits/stdc++.h> using namespace std; #define FOR(i,a,n) for (auto i = (a), i ## __ = (n); i <= i ## __; ++i) #define FORD(i,a,n) for (auto i = (a), i ## __ = (n); i >= i ## __; --i) #define REP(i,n) FOR(i, 0, n - 1) #define ALL(x) x.begin(), x.end() #define SZ(x) (int(x.size())) #define EB emplace_back #define ST first #define ND second #define tpv typedef vector< typedef long long LL; typedef pair<int, int> PII; tpv int> VI; tpv VI> VVI; tpv PII> VPII; tpv LL> VLL; constexpr char nl = '\n'; #define endl nl #define ris return *this #define tem template<class T tem, class B> inline void mini(T&& a, B&& b) { if (b < a) a = b; } tem, class B> inline void maxi(T&& a, B&& b) { if (b > a) a = b; } int ceil2(int x) { return x < 2 ? 1 : 1 << (sizeof(x) * 8 - __builtin_clz(x - 1)); } tem> struct Dump { T a, b; }; tem> auto dump(T&& x) -> Dump<decltype(x.begin())> { return {ALL(x)}; } struct Debug { ~Debug() { cerr << endl; } tem> auto operator<<(T x) -> decltype(cerr << x, *this) { cerr << boolalpha << x; return *this; } tem> auto operator<<(T x) -> decltype(x.begin(), *this) { auto a = x.begin(), b = x.end(); *this << "{"; for (; a != b;) *this << *a++, *this << (a == b ? "" : " "); return *this << "}"; } tem, class B> Debug& operator<<(pair<T, B> p) { ris << "(" << p.ST << ", " << p.ND << ")"; } tem> Debug& operator<<(Dump<T> d) { *this << "{\n"; for (T a = d.a, c = a; a != d.b; ++a) *this << " " << distance(c, a) << ": " << *a << '\n'; ris << "}"; } }; struct Foo {tem>Foo& operator<<(T) {ris;}}; #ifdef DEBUG # define DEB(x...) x # define deb Debug() #else # define DEB(...) # define deb Foo() #endif #define imie(x...) #x ": " << (x) << " " #define LOG(x...) deb << imie(x) #define DOG(x...) deb << #x ": " << dump(x) << " " int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, kk; cin >> n >> kk; vector<vector<char>> P(n + 2, vector<char>(n + 2, '.')); FOR (i, 1, n) FOR (j, 1, n) cin >> P[i][j]; constexpr int di[] = {-1, 1, 0, 0}; constexpr int dj[] = {0, 0, -1, 1}; int res = 0; FOR (i, 1, n) FOR (j, 1, n) if (P[i][j] == '.') REP (k, 4) if (P[i + di[k]][j + dj[k]] == '#') { ++res; break; } cout << res << nl; return 0; } |