#include #include #include #include #include auto boolmat(int n, int m) { return std::vector>(n, std::vector(m, false)); } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, m; std::cin >> n >> m; auto b = boolmat(m, m); const int s = n >= 3 ? (n - 3) * (n - 3) : 0; auto c = boolmat(m, s); for (int i = 0; i < m; ++i) { auto a = boolmat(n, n); for (auto &&v : a) { for (auto &&e : v) { char t; std::cin >> t; e = t != '.'; } } std::array dx = {-2, -2, -1, -1, 0, 0, 1, 1}; std::array dy = {-1, 0, -2, 1, -2, 1, -1, 0}; int j = 0; for (int x = 2; x + 2 <= n; ++x) { for (int y = 2; y + 2 <= n; ++y) { bool t = false; for (int k = 0; k < 8; ++k) { t = t != a[x + dx[k]][y + dy[k]]; } c[i][j] = t; ++j; } } } { std::vector idx(m); std::iota(idx.begin(), idx.end(), 0); for (int j = 0; j < s; ++j) { std::vector f, t; for (const int i : idx) { if (c[i][j]) { t.push_back(i); } else { f.push_back(i); } } std::copy(f.cbegin(), f.cend(), idx.begin()); std::copy(t.cbegin(), t.cend(), idx.begin() + f.size()); } std::vector list; for (int k = 0; k < m; ++k) { const int i = idx[k]; if (k != 0 && c[idx[k - 1]] != c[i]) { list.clear(); } for (const int j : list) { b[i][j] = true; } list.push_back(i); } } for (int i = 0; i < m; ++i) { for (int j = 0; j < m; ++j) { if (i < j) { std::cout << (b[i][j] || b[j][i] ? '1' : '0'); } } std::cout << '\n'; } }