8684: Half Turns

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:6 通过:1

题目描述


Given two even integers nnn and mmm, construct a matrix MMM satisfying following constraints:
  • The number of rows and columns of MMM are nnn and mmm respectively.
  • For each integer iii (1≤i≤nm)(1 \le i \le nm)(1inm), iii appears exactly once in MMM.
  • For each two adjacent integers iii and i+1i+1i+1 (1≤i<nm)(1 \le i < nm)(1i<nm), denoting Mx1,y1=iM_{x_1,y_1} = iMx1,y1=i and Mx2,y2=i+1M_{x_2,y_2} = i+1Mx2,y2=i+1, then ∣x1−x2∣+∣y1−y2∣=1|x_1 - x_2| + |y_1 - y_2| = 1x1x2+y1y2=1 holds.
  • The number of turning integers is exactly nm2\frac{nm}{2}2nm, where iii (1<i<nm)(1 < i < nm)(1<i<nm) is a turning integer iff the three integers i−1i-1i1, iii and i+1i+1i+1 are not in the same row or the same column.
If multiple solution exist, print any one of them. If no solution exist, report it.

输入格式


The only line contains two even integers nnn and mmm (2≤n,m≤1000)(2 \le n,m \le 1\,000)(2n,m1000).




输出格式

If no solution, print "No" (without quotes) in one line.
If solution exists, print "Yes" (without quotes) in the first line. Then print nnn lines each containing mmm integers Mi,1,Mi,2,⋯,Mi,mM_{i,1}, M_{i,2}, \cdots, M_{i,m}Mi,1,Mi,2,,Mi,m, denoting the answer matrix.

输入样例 复制

4 4

输出样例 复制

Yes
4 5 6 7
3 10 9 8
2 11 14 15
1 12 13 16

数据范围与提示


In the sample case, the number of turning integers is 888, which equals 4×42\frac{4\times 4}{2}24×4, and the 8 turning integers are 2,5,6,8,9,11,12,152,5,6,8,9,11,12,152,5,6,8,9,11,12,15.

分类标签