Logo
(追記) (追記ここまで)

24829번 - Counting Codes 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 (추가 시간 없음) 1024 MB7000.000%

문제

Graphic by Henry Wang.

You're one of the king's spies sent on a secret mission to retrieve an item of incredible value, an ancient scroll from the throne room. Legend has it, the scroll contains the answer to the $P$ versus $NP$ problem. When you finally reach the throne room, you realize there is a code the guards enter every day while observing them. As a spy, you've started to notice a few rules for each guard's code:

  1. each code is a matrix consisting of nonzero decimal digits (integers from 1ドル$ to 9ドル$) with $m$ rows and $n$ columns
  2. no digit repeats within any row of the code
  3. for each digit $l$ in the code, except for those in the topmost row and rightmost column, let $u$ be the digit above it and let $r$ be the digit to its right in the code matrix. Then one of the following must be true:
    • $u$ is the product of $l$ and $r$
    • $u$ is the sum of $l$ and $r$
    • $u$ is the difference of $l$ and $r$ or $r$ and $l$
    • $u$ is the quotient of $l$ and $r$ or $r$ and $l$

On day 999ドル,ドル you've noticed a guard has seem to walked off while entering his code. Some digits have been omitted, but after careful consideration you think you can crack the code. Digits that have been omitted are represented with a 0ドル$. How many complete codes are possible, given the guard's partial code?

입력

A test case starts with a line containing two numbers $m$ (3ドル \le m \le 6$) and $n$ (3ドル \le n \le 6$), which is the number of rows and number of columns of the grid. The following $m$ lines contain $n$ integers from 0ドル$ to 9ドル,ドル separated by spaces. 0ドル$ indicates an unknown value that you can supply, and there will be at most $\lfloor \frac{m*n}{2} \rfloor$ unknown values.

You can assume the guard has followed the rules with the partial code (i.e. no repeated digits appear in any row in the input, and any three pairs of non-zero digits that form an L have the property described above).

출력

For each test case, print the number of complete codes you can find.

제한

예제 입력 1

3 3
1 2 4
0 3 6
4 0 3

예제 출력 1

2

예제 입력 2

3 4
2 3 0 7
0 0 2 1
0 0 3 0

예제 출력 2

37

예제 입력 3

3 4
1 3 0 7
2 0 0 1
0 0 9 0

예제 출력 3

14

힌트

출처

School > Virginia Tech High School Programming Contest > 2019 Virginia Tech High School Programming Contest L번

  • 문제를 만든 사람: Henry Wang
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /