/* -*- coding: utf-8 -*- * * 1974.cc: No.1974 2x2 Flipper - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_H = 1000; const int MAX_W = 1000; /* typedef */ /* global variables */ int as[MAX_H][MAX_W]; /* subroutines */ void printans(int h, int w, int c) { printf("%d\n", c); for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) printf("%d%c", as[i][j], (j + 1 < w) ? ' ' : '\n'); } /* main */ int main() { int h, w; scanf("%d%d", &h, &w); int c = 0; if (h > 1 && w > 1 && (h & w & 1)) { for (int i = 0; i < h; i++) fill(as[i], as[i] + w, 1); c = h * w; if (h <= w) { for (int y = 0, x = 0, d = 1; x < w;) { for (int i = 0; i < d; i++) as[y][x++] = 0, c--; if (++y >= h) y = 0, d = 2; } } else { for (int x = 0, y = 0, d = 1; y < h;) { for (int i = 0; i < d; i++) as[y++][x] = 0, c--; if (++x >= w) x = 0, d = 2; } } } else { int he = h & ~1, we = w & ~1; for (int i = 0; i < he; i++) for (int j = 0; j < we; j++) as[i][j] = 1, c++; } printans(h, w, c); return 0; }