#include #define MAX_N 200 bool solve(const std::vector > &a) { int n = a.size(); std::bitset<2 * MAX_N - 1> plus; std::bitset<2 * MAX_N - 1> minus; for (int i = 2; i < 2 * n - 1; i += 2) { int x = (i - 2) >> 1; int y = n - 2 - x; minus[i] = minus[i - 2] ^ a[x][y] ^ a[x + 1][y] ^ a[x][y + 1] ^ a[x + 1][y + 1]; } for (int i = 3; i < 2 * n - 1; i += 2) { int x = (i - 3) >> 1; int y = n - 3 - x; minus[i] = minus[i - 2] ^ a[x][y] ^ a[x + 1][y] ^ a[x][y + 1] ^ a[x + 1][y + 1]; } for (int i = n - 4; i >= 0; i--) plus[i] = plus[i + 2] ^ minus[n - i] ^ minus[n - 2 - i] ^ a[0][i] ^ a[1][i] ^ a[0][i + 1] ^ a[1][i + 1]; for (int i = n + 1; i < 2 * n - 1; i++) plus[i] = plus[i - 2] ^ minus[i - n] ^ minus[i - n + 2] ^ a[i - n][n - 2] ^ a[i - n + 1][n - 2] ^ a[i - n][n - 1] ^ a[i - n + 1][n - 1]; // reverse minus for (int i = 0; i < n; i++) { bool tmp = minus[i]; minus[i] = minus[2 * n - 2 - i]; minus[2 * n - 2 - i] = tmp; } auto b = a; for (int i = 0; i < n; i++) b[i] ^= (plus >> i) ^ (minus >> (n - 1 - i)); auto l0 = b[0] << (2 * MAX_N - 1 - n); auto l1 = ~b[0] << (2 * MAX_N - 1 - n); for (int i = 1; i < n; i++) { auto r0 = b[i] << (2 * MAX_N - 1 - n); if (r0 != l0 && r0 != l1) return false; } return true; } int main() { clock_t r0 = clock(); int n, m; scanf("%d%d", &n, &m); std::vector > a[m]; for (int i = 0; i < m; i++) { a[i].resize(n); for (int j = 0; j < n; j++) { std::string s; std::cin >> s; for (int k = 0; k < n; k++) a[i][j][k] = s[k] == '#'; } } clock_t r1 = clock(); std::vector res; for (int i = 0; i + 1 < m; i++) { std::vector > tmp(n); std::string cur; for (int j = i + 1; j < m; j++) { for (int k = 0; k < n; k++) tmp[k] = a[i][k] ^ a[j][k]; cur.push_back(solve(tmp) ? '1' : '0'); } res.push_back(cur); } clock_t r2 = clock(); for (auto i : res) std::cout << i << std::endl; clock_t r3 = clock(); std::cerr << (double) (r1 - r0) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl; std::cerr << (double) (r2 - r1) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl; std::cerr << (double) (r3 - r2) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl; return 0; }