407156: GYM102697 127 Latin Squares
Memory Limit:256 MB
Time Limit:8 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
127. Latin Squarestime limit per test8 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output
A latin square is defined as a 4 by 4 grid of numbers, where all of the numbers in each row and column are distinct, i.e. no two pairs of elements in each row and column are equal.
You're given a partially filled in latin square. Figure out how many valid latin squares can be formed by filling in the empty digits of the latin square.
InputThe input consists of 4 lines, each consisting of 4 integers: the digits in the latin square. For each digit, if it has already been filled in, it will be represented with a digit from 1 to 4, and if it hasn't been filled in yet, it will be represented with a "0".
OutputOutput a single positive integer $$$n$$$: the number of ways to fill in the latin square as described above.
ExamplesInput0000 0000 0000 0000Output
576Input
1234 2341 3412 0000Output
1Input
1234 2341 3412 4311Output
0