#P13282. [GCJ 2013 Qualification] Lawnmower

[GCJ 2013 Qualification] Lawnmower

题目描述

Alice and Bob have a lawn in front of their house, shaped like an NN metre by MM metre rectangle. Each year, they try to cut the lawn in some interesting pattern. They used to do their cutting with shears, which was very time-consuming; but now they have a new automatic lawnmower with multiple settings, and they want to try it out.

The new lawnmower has a height setting - you can set it to any height hh between 11 and 100100 millimetres, and it will cut all the grass higher than hh it encounters to height hh. You run it by entering the lawn at any part of the edge of the lawn; then the lawnmower goes in a straight line, perpendicular to the edge of the lawn it entered, cutting grass in a swath 11m wide, until it exits the lawn on the other side. The lawnmower's height can be set only when it is not on the lawn.

Alice and Bob have a number of various patterns of grass that they could have on their lawn. For each of those, they want to know whether it's possible to cut the grass into this pattern with their new lawnmower. Each pattern is described by specifying the height of the grass on each 11m x 11m square of the lawn.

The grass is initially 100100mm high on the whole lawn.

输入格式

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case begins with a line containing two integers: NN and MM. Next follow NN lines, with the iith line containing MM integers ai,ja_{i,j} each, the number ai,ja_{i,j} describing the desired height of the grass in the jjth square of the iith row.

输出格式

For each test case, output one line containing "Case #xx: yy", where xx is the case number (starting from 11) and yy is either the word "YES" if it's possible to get the xx-th pattern using the lawnmower, or "NO", if it's impossible (quotes for clarity only).

3
3 3
2 1 2
1 1 1
2 1 2
5 5
2 2 2 2 2
2 1 1 1 2
2 1 2 1 2
2 1 1 1 2
2 2 2 2 2
1 3
1 2 1
Case #1: YES
Case #2: NO
Case #3: YES

提示

Limits

  • 1T100.1 \leq T \leq 100.

Small dataset (10 Pts, Test set 1 - Visible)

  • 1N,M10.1 \leq N, M \leq 10.
  • 1ai,j2.1 \leq a_{i,j} \leq 2.

Large dataset (30 Pts, Test set 2 - Hidden)

  • 1N,M100.1 \leq N, M \leq 100.
  • 1ai,j100.1 \leq a_{i,j} \leq 100.