問題一覧 > 通常問題

No.3567 Modulo Grid

レベル : / AI推定難易度 : 2500 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 1024 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 12
作問者 : 👑 to-omer / テスター : 👑 hamamu
お気に入りにしたユーザー ProblemId : 9888 / 自分の提出
問題文最終更新日: 2026-04-18 16:55:04
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 501 (順位表) の他の問題:

Problem Statement

You are going to write every integer from $1$ to $M=H\times W$, inclusive, $1$ time each into the cells of a grid with $H$ rows and $W$ columns.
Find $1$ way of writing them that satisfies the following condition.

  • For any $2$ cells adjacent in one of the $4$ directions (up, down, left, right), the integers $a,b$ written in them form a good pair

Here, integers $a,b$ form a good pair if at least one of the following conditions holds.

  • There exists an integer $x$ such that $ax\equiv b \bmod M$
  • There exists an integer $x$ such that $a\equiv bx \bmod M$

It can be proved that a way of writing satisfying the condition always exists under the constraints of this problem.

Constraints

  • All inputs are positive integers
  • $1\le H\times W\le 2\times 10^5$

Input

$H$ $W$

Output

Output $1$ way of writing that satisfies the condition, in the following format. Here, $A_{i,j}$ is the number written in row $i$, column $j$.

$A_{1,1}$ $A_{1,2}$ $\dots$ $A_{1,W}$
$A_{2,1}$ $A_{2,2}$ $\dots$ $A_{2,W}$
$\vdots$
$A_{H,1}$ $A_{H,2}$ $\dots$ $A_{H,W}$

Sample

Sample 1
Input
2 3
Output
1 2 4
3 5 6

In this grid, every positive integer from $1$ to $2\times 3=6$ is written $1$ time each, and the $2$ positive integers written in any $2$ adjacent cells form a good pair.

With the following way of writing, there exists neither an $x$ satisfying $2x\equiv 3\bmod 6$ nor an $x$ satisfying $2\equiv 3x\bmod 6$, so $2,3$ is not a good pair.

1 2 3
4 5 6
Sample 2
Input
1 1
Output
1

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。