시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB45191438.889%

문제

Primonimo is a game played on an n × m board filled with numbers taken from the range 1 . . . p for some prime number p. At each move, a player selects a square and adds 1 to the numbers in all squares in the same row and column as the selected square. If a square already shows the number p, it wraps around to 1.

The game is won if all squares show p. Given an initial board, find a sequence of moves that wins the game!

입력

The input consists of a single test case. The first line contains three numbers n m p denoting the number of rows n (1 ≤ n ≤ 20), the number of columns m (1 ≤ m ≤ 20), and a prime number p (2 ≤ p ≤ 97). Each of the next n lines consists of m numbers in the range 1 . . . p.

출력

If a winning sequence of at most p · m · n moves exists, output an integer k ≤ p · m · n denoting the number of moves in the sequence. Then output k moves as a sequence of integers that numbers the board in row-major order, starting with 1. If there are multiple such sequences, you may output any one of them. If no winning sequence exists, output -1.

예제 입력 1

4 5 5
2 1 1 1 2
5 3 4 4 3
4 3 3 3 2
3 1 3 3 1

예제 출력 1

6
19 12 2 18 5 5

예제 입력 2

3 3 3
3 1 1
1 3 2
3 2 3

예제 출력 2

13
4 2 6 1 9 7 5 5 7 1 2 3 3

예제 입력 3

3 2 2
1 2
2 1
1 2

예제 출력 3

-1

예제 입력 4

3 2 2
2 1
2 1
1 1

예제 출력 4

1
6

출처

ICPC > Regionals > North America > North America Qualification Contest > ACM-ICPC North America Qualifier 2016 I번

  • 스페셜 저지를 만든 사람: ho94949
  • 문제를 만든 사람: Godmar Back