아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Gardening

시간 제한0.2초메모리 제한1024 MB

요약
N×M 격자를 K가지 꽃으로 채우되 각 종류가 하나의 변으로 연결된 영역을 이루고 모든 칸이 같은 종류인 이웃을 정확히 두 개 갖도록 만들 수 있는지 판정하고, 가능하면 하나를 구성한다.
난이도

보통10점 중 7점

유형
구현, 그리디, 수학, 시뮬레이션
정답자
아직 제출이 없습니다

문제

Azusa, the witch of the highlands, wants to do a fun activity with her friend Laika: gardening. They want to make a rectangular garden NN meters tall by MM meters wide. The garden is divided into 1 meter by 1 meter squares. The question is: what flowers should they plant?

Laika has found KK different types of flowers. Azusa and Laika will plant one type of flower in each 1 meter by 1 meter square. Furthermore, for aesthetic reasons, the garden must satisfy the following constraints:

  1. Each flower type must appear at least once in the garden.
  2. For any two squares where the same flower type is planted, a path between them where all the intermediate squares have the same type of flower must exist. For example, the following gardens are not allowed:

  1. Any square must have exactly two adjacent squares planted with the same type of flower. For example, the following gardens are not allowed:

Note that, in the previous constraints, two squares are “adjacent” if and only if they share a common edge (not merely a corner); and a path is a sequence of adjacent squares.

You are given TT different values for NN, MM and KK. Help Azusa and Laika create gardens that satisfy the conditions for each test case — or, tell them that it is impossible to do this.

입력

The first line of the input contains the integer TT. Afterwards, TT lines follow, each describing a test case. Each test case consists of three integers NN, MM and KK.

출력

Output the answers for each test case in order. For a test case, if no solution exists, output NO on a single line. Otherwise, first output YES on a single line, and then output N×MN \times M integers arranged in NN lines and MM columns describing the required garden. The lines and columns of the output correspond to the lines and columns of the garden, with each integer corresponding to a 1 meter by 1 meter square. The integers represent the types of flowers planted in the squares, where the types are indexed from 11 to KK. If there are multiple correct solutions you may output any of them.

제한

  • 1≤N,M≤200,0001 ≤ N, M ≤ 200\\,000.
  • 1≤K≤N×M1 ≤ K ≤ N \times M.
  • Let SS equal the sum of N×MN \times M for all the test cases in a file for which an answer exists (i.e. where the output is not NO).
  • S≤200,000S ≤ 200\\,000.

힌트

For the first test case, we note that no 2 by 2 garden with 2 types of flowers is possible. Thus we output NO. The other gardens are pictured below:

예제1

  1. 예제 1

    입력
    5
    2 2 2
    2 2 1
    4 4 4
    4 4 2
    4 6 3
    
    예상 출력
    NO
    YES
    1 1
    1 1
    YES
    1 1 2 2
    1 1 2 2
    3 3 4 4
    3 3 4 4
    YES
    1 1 1 1
    1 2 2 1
    1 2 2 1
    1 1 1 1
    YES
    1 1 1 1 1 1
    1 2 2 3 3 1
    1 2 2 3 3 1
    1 1 1 1 1 1