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
| #include <cstdio> #include <bitset> using namespace std; template <class Type> void read(Type &x) { char c; bool flag = false; while ((c = getchar()) < '0' || c > '9') c == '-' && (flag = true); x = c - '0'; while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0'; flag && (x = ~x + 1); } template <class Type> void write(Type x) { x < 0 && (putchar('-'), x = ~x + 1); x > 9 && (write(x / 10), 0); putchar(x % 10 + '0'); } const int N = 1610, dx[] = {0, 1, -1, 0}, dy[] = {1, 0, 0, -1}; int n, m, tot; bitset<N> A[N]; void Gauss () { for (int k = 1; k <= tot; k++) { int t = k; while (t <= tot && !A[t][k]) t++; t > tot ? A[k][0] = 1 : (swap(A[t], A[k]), 0); for (int i = 1; i <= tot; i++) i ^ k && A[i][k] && (A[i] ^= A[k], 0); } } int num (int a, int b) { return (a - 1) * m + b; } bool inside (int a, int b) { return a > 0 && a <= n && b > 0 && b <= m; } int main () { read(n), read(m); tot = n * m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { int p = num(i, j); for (int k = 0; k < 4; k++) { int nx = i + dx[k], ny = j + dy[k]; if (inside(nx, ny)) A[p][num(nx, ny)] = 1; } A[p][p] = 1; } Gauss(); for (int i = 1; i <= n; i++, puts("")) for (int j = 1; j <= m; j++, putchar(' ')) write(A[num(i, j)][0]); return 0; }
|