CF45J.Planting Trees

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vasya is a Greencode wildlife preservation society proponent. One day he found an empty field nobody owned, divided it into n×mn×m squares and decided to plant a forest there. Vasya will plant nmnm trees of all different heights from 11 to nmnm . For his forest to look more natural he wants any two trees growing in the side neighbouring squares to have the absolute value of difference in heights to be strictly more than 1. Help Vasya: make the plan of the forest planting for which this condition is fulfilled.

输入格式

The first line contains two space-separated integers nn and mm ( 1<=n,m<=1001<=n,m<=100 ) — the number of rows and columns on Vasya's field

输出格式

If there's no solution, print -1. Otherwise, print nn lines containing mm numbers each — the trees' planting plan. In every square of the plan the height of a tree that should be planted on this square should be written. If there are several solutions to that problem, print any of them.

输入输出样例

  • 输入#1

    2 3
    

    输出#1

    3 6 2
    5 1 4
    
  • 输入#2

    2 1
    

    输出#2

    -1
    
首页