#P16118. [USTCPC 2026] Filling with Z-shape

    ID: 18111 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>数学Special Judge构造2026Ad-hoc高校校赛

[USTCPC 2026] Filling with Z-shape

Problem Description

There is an m×nm \times n grid, with coordinates indexed starting from 00. Initially, every cell contains −1-1.

In one operation, you may choose a "Z-shaped" region (see the picture; rotations and reflections are allowed), and negate all numbers in that region.

Given m,nm, n, determine whether there exists a sequence of operations that turns all numbers in the grid into 11.

If no such sequence exists, output Impossible!.

Input Format

The input contains two integers m,nm, n ($2\leq m,n\leq 2\times 10^5, 4\leq mn \le 2\times 10^5$), representing the number of rows and columns of the grid.

Output Format

If a solution exists, output an operation sequence: on the first line output the number of operations rr (0≤r≤1060\leq r\leq 10^6), then output rr lines, each containing 88 integers, representing the coordinates of the four cells of the "Z-shape" (in the order x1,y1,x2,y2,x3,y3,x4,y4x_1,y_1,x_2,y_2,x_3,y_3,x_4,y_4; the order of the four points can be arbitrary). If no solution exists, output Impossible!. If there are multiple solutions, output any one of them.

It can be proven that if a valid solution exists, then there must exist a valid solution with 0≤r≤1060\leq r \leq 10^6.

2 4
4
0 0 0 1 1 1 1 2
1 0 1 1 0 1 0 2
1 3 0 1 1 2 0 2
1 1 1 2 0 2 0 3
2 5
Impossible!

Hint

Translated by ChatGPT 5