ユニークビジョンプログラミングコンテスト2026 夏(AtCoder Regular Contest 226)
C
正方形顶点填充
Square Corner Packing
AtCoder
⌀ 2070
原题
← BD →

正方形顶点填充AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

There is a grid with $H$ rows and $W$ columns. Let $(i,j)$ denote the cell at the $i$-th row from the top and the $j$-th column from the left. Initially, all cells are white.

有一个 $H$ 行 $W$ 列的网格。令 $(i,j)$ 表示从上往下第 $i$ 行、从左往右第 $j$ 列的单元格。初始时,所有单元格均为白色。AI (CI翻译)

You may perform the following operation any number of times.

你可以进行任意次以下操作。AI (CI翻译)

  • Choose integers $r,c,s$ satisfying all of the following conditions, and paint the cells $(r,c),(r+s,c),(r,c+s),(r+s,c+s)$ black.
  • $1\le r<r+s\le H$
    • $1\le c<c+s\le W$
    • The cells $(r,c),(r+s,c),(r,c+s),(r+s,c+s)$ are all white.
  • 选择满足以下所有条件的整数 $r,c,s$,并将单元格 $(r,c),(r+s,c),(r,c+s),(r+s,c+s)$ 涂成黑色。
  • $1\le r<r+s\le H$
    • $1\le c<c+s\le W$
    • 单元格 $(r,c),(r+s,c),(r,c+s),(r+s,c+s)$ 全部为白色。
AI (CI翻译)

Find the maximum number of operations you can perform, and output one sequence of operations that achieves that maximum.

求最多可以进行多少次操作,并输出一组能够达到该最大次数的操作序列。AI (CI翻译)

You are given $T$ test cases; solve each of them.

给定 $T$ 组测试数据,请分别求解每组数据。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1\le T\le 500$
  • $2\le H,W\le 500$
  • The sum of $HW$ over all test cases is at most $250000$.
  • All input values are integers.
  • $1\le T\le 500$
  • $2\le H,W\le 500$
  • 所有测试数据的 $HW$ 之和不超过 $250000$。
  • 所有输入值均为整数。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The input is given from Standard Input in the following format:

输入通过标准输入给出,格式如下:AI (CI翻译)

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
AI (CI翻译)

Each test case is given in the following format:

每组测试数据的格式如下:AI (CI翻译)

H W

H W
AI (CI翻译)

Output

输出格式

AI (CI翻译)

For each test case, let $K$ be the maximum possible number of operations, and let $r_i,c_i,s_i$ be the integers chosen in the $i$-th operation; output them in the following format:

对于每组测试数据,令 $K$ 为最多可以进行的操作次数,令 $r_i,c_i,s_i$ 表示第 $i$ 次操作中选择的整数。请按照以下格式输出:AI (CI翻译)

K
r_1 c_1 s_1
r_2 c_2 s_2
\vdots
r_K c_K s_K

K
r_1 c_1 s_1
r_2 c_2 s_2
\vdots
r_K c_K s_K
AI (CI翻译)

If there are multiple sequences of operations that achieve the maximum, any of them will be accepted.

如果有多组操作序列都能达到最大次数,输出其中任意一组即可通过。AI (CI翻译)

样例

Input #1
2
5 6
2 2
Output #1
6
1 1 3
3 4 2
1 2 3
3 3 2
1 3 3
2 1 1
1
1 1 1
For the first test case, performing the six output operations paints the following cells black. The digit $i$ represents a cell painted black by the $i$-th operation, and `.` represents a cell that is never painted. There are other outputs that will be accepted.
题目信息

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。