logo AlgoBeat OnlineJudge
登录 注册

#213717. [NWRRC 2023] Loops

内存限制:1024 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Consider four integers , , , and , such that . Let's put them in the corners of a square in some order and draw a loop . Depending on the arrangement of the integers, we can get different loop shapes, but some arrangements produce the same shape:

There are three possible loop shapes we can get:

Now consider an matrix filled with distinct integers from to , inclusive. Each square in this matrix can be seen as a square with integers in its corners. Let's build a loop for each of these squares like we did before:

Your task is to perform the inverse operation. You are given the shape types for all loops, and you need to build an matrix filled with distinct integers from to , inclusive, that produces these shapes.

输入格式

The first line contains two integers and ().

Each of the next lines contains a string of characters without spaces. Each character is a digit from to , denoting the type of the shape of the corresponding loop.

输出格式

Print an matrix filled with distinct integers from to , inclusive, that produces the shapes of the loops in the input.

It can be shown that such a matrix always exists. If there are multiple answers, print any of them.

样例

样例输入 1

3 4
113
231

样例输出 1

9 11 7 12
4 6 1 8
2 10 5 3