Seating of Students

题意翻译

# 题目背景 学生们进入了一个班级考试并以某种方式就坐。老师认为:“也许他们这样坐是为了抄别人的答案,我需要重新编排他们,并使原来相邻的人不再相邻。” # 题目描述 这个班可以被想象成一个n行m列的矩阵,切每一个矩阵都在其中的一个单元格中。我们这样定义两个学生相邻:若A学生在B学生的上下左右任意一个方向,则称A与B相邻。 我们给学生这样编号:坐在i行j列的学生的编号为(i-1)*m+j。 你需要找到一个n行m列的矩阵,其中每个学生出现且仅出现一次,并且满足老师的要求。否则,我们称没有这样的座位顺序矩阵。 # 输入描述: 输入包含两个整数n,m (1<=n,m<=10^5且n*m<10^5); (n代表行数,m代表列数) # 输出描述 若没有符合要求的矩阵,输出“NO”(不含引号) 反之,如果有这样的矩阵,输出“YES”(不含引号)并输出这个矩阵。 # 样例解释 #### 样例1: 初始矩阵看起来像这样: 1 2 3 4 5 6 7 8 显而易见,在答案中没有两个学生不符合条件。 #### 样例2: 这里只有两个可能的座位,而不管怎样坐编号为1的同学与编号为2的同学都是相邻的,所以不存在。 翻译提供:masiyuan

题目描述

Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating." The class can be represented as a matrix with $ n $ rows and $ m $ columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side. Let's enumerate students from $ 1 $ to $ n·m $ in order of rows. So a student who initially sits in the cell in row $ i $ and column $ j $ has a number $ (i-1)·m+j $ . You have to find a matrix with $ n $ rows and $ m $ columns in which all numbers from $ 1 $ to $ n·m $ appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix.

输入输出格式

输入格式


The only line contains two integers $ n $ and $ m $ ( $ 1<=n,m<=10^{5} $ ; $ n·m<=10^{5} $ ) — the number of rows and the number of columns in the required matrix.

输出格式


If there is no such matrix, output "NO" (without quotes). Otherwise in the first line output "YES" (without quotes), and in the next $ n $ lines output $ m $ integers which form the required matrix.

输入输出样例

输入样例 #1

2 4

输出样例 #1

YES
5 4 7 2 
3 6 1 8 

输入样例 #2

2 1

输出样例 #2

NO

说明

In the first test case the matrix initially looks like this: `<br></br>1 2 3 4<br></br>5 6 7 8<br></br>`It's easy to see that there are no two students that are adjacent in both matrices. In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors.