#P13998. 【MX-X19-T7】「LAOI-14」夜に駆ける

【MX-X19-T7】「LAOI-14」夜に駆ける

Description

Given positive integers n,mn, m, with the guarantee that mm is even.

There is a robot in an n×mn \times m non-negative integer matrix AA. The rows are numbered 1n1 \sim n, and the columns are numbered 1m1 \sim m. Let the current position of the robot be (x,y)(x, y), initially (x,y)=(1,1)(x, y) = (1, 1). The robot cyclically performs the following operations:

  1. Move to y1y-1 or y+1y+1 or do not move (it must not move outside the matrix).
  2. Move down one step. If this move goes beyond the matrix size, the loop stops.

Your task is to construct an n×mn \times m matrix AA, where each row of the matrix contains exactly m2\frac{m}{2} zeros and m2\frac{m}{2} ones, such that the sum of all Ai,jA_{i,j} that the robot passes through is minimized. The robot is infinitely smart and will choose the route that maximizes the sum of Ai,jA_{i,j} it passes through. Note that the initial position is also considered as passed by the robot. If there are multiple optimal solutions, you may output any one of them.

Input Format

One line containing two positive integers n,mn, m, with the guarantee that mm is even.

Output Format

Output nn lines, each containing mm non-negative integers (either 00 or 11), representing the constructed matrix.

This problem uses a custom checker. If there are multiple solutions, output any valid one.

2 4
0 0 1 1
0 0 1 1

Hint

【Sample Explanation】

For the first sample, the optimal path for the robot is:

  1. Start at (1,1)(1,1), A1,1=0A_{1,1}=0;
  2. Move to (1,2)(1,2), A1,2=0A_{1,2}=0;
  3. Move to (2,2)(2,2), A2,2=0A_{2,2}=0;
  4. Move to (2,3)(2,3), A2,3=1A_{2,3}=1.

The total sum of Ai,jA_{i,j} values that the robot passes through is 11. Clearly, no better construction exists.

【Data Range】

This problem uses bundled testing.

Subtask ID nn \le mm Special Properties Score
11 66 6\le 6 None 55
22 5×1035\times 10^3 =4=4
33 =8=8 1515
44 5×103\le 5\times 10^3 n<mn < m 3030
55 None 4545

For all test cases, 2n,m5×1032 \le n, m \le 5 \times 10^3, and mm is even.

Translated by DeepSeek V3.1