#include #define VARNAME(x) #x #define show(x) cerr << #x << " = " << x << endl using namespace std; using ll = long long; using ld = long double; template vector Vec(int n, T v) { return vector(n, v); } template auto Vec(int n, Args... args) { auto val = Vec(args...); return vector(n, move(val)); } template ostream& operator<<(ostream& os, const vector& v) { os << "sz:" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = (ll)1e9 + 7LL; constexpr ld PI = static_cast(3.1415926535898); template constexpr T INF = numeric_limits::max() / 10; struct Graph { Graph(const int n) { edge.resize(n); } void addEdge(const int from, const int to) { edge[from].push_back(to); edge[to].push_back(from); } vector> edge; }; int N; int ans; int num; void MaximumIndependentSet(const Graph& g, const vector& used, const int use, const int res) { if (use + res <= ans) { return; } ans = max(ans, use); for (int i = 0; i < num; i++) { if (not used[i]) { vector tmp = used; int tmpres = res - 1; for (const int to : g.edge[i]) { if (not used[to]) { tmpres--; tmp[to] = true; } } MaximumIndependentSet(g, tmp, use + 1, tmpres); } } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; vector ok(4 * N, true); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { char c; cin >> c; if (c == '#') { if (i < N - 2) { ok[j] = false; ok[N + j] = false; } else if (i == N - 1) { ok[N + j] = false; } if (j < N - 2) { ok[2 * N + i] = false; ok[2 * N + N + i] = false; } else if (i == N - 1) { ok[2 * N + N + i] = false; } } } } map mp; for (int i = 0; i < 4 * N; i++) { if (ok[i]) { mp[i] = num; num++; } } Graph g(num); for (int i = 0; i < 4 * N; i++) { if (not ok[i]) { continue; } vector> tmp(N, vector(N, true)); if (i < 2 * N) { for (int j = 0; j < N - 1; j++) { tmp[i / N + j][i % N] = false; } } else { for (int j = 0; j < N - 1; j++) { tmp[(i - 2 * N) % N][(i - 2 * N) / N + j] = false; } } for (int j = i + 1; j < 4 * N; j++) { if (not ok[j]) { continue; } if (j < 2 * N) { for (int k = 0; k < N - 1; k++) { if (not tmp[j / N + k][j % N]) { g.addEdge(mp[i], mp[j]); break; } } } else { for (int k = 0; k < N - 1; k++) { if (tmp[(j - 2 * N) % N][(j - 2 * N) / N + k]) { g.addEdge(mp[i], mp[j]); break; } } } } } vector used(num, false); MaximumIndependentSet(g, used, 0, num); cout << ans << endl; return 0; }