Enigma of the Jewelry Case

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

요약
각 행과 열이 증가하도록 정렬된 N x N 격자가 주어질 때, 원래 배열로 되돌리는 데 필요한 90도 반시계 방향 회전 횟수의 최솟값을 구한다.
난이도

보통10점 중 4점

유형
구현, 행렬
정답자
아직 제출이 없습니다

문제

The princess of Nlogonia keeps her pearl collection in a square jewelry case made up of NN columns, each column containing NN small boxes. She places a different number of pearls in each box, and arranges the box so that in each column, from top to bottom, the boxes contain an increasing number of pearls and in each row, from left to right, the boxes also contain an increasing number of pearls.

The princess suspects that her little sister, who is very mischievous, is messing with her things in her games. In particular, the princess suspects that her jewelry case has been rotated 9090 degrees clockwise, possibly multiple times.

Figure (a) below shows an example of the original arrangement of a 4×44 \times 4 case. Figure (b) shows the case rotated clockwise, 9090 degrees, once.

Given the number of pearls in each box, write a program to determine the smallest number of 9090-degree counterclockwise rotations that are necessary to return the jewelry case to its original state.

입력

The first line of the input contains an integer NN, the number of rows and columns in the case (2≤N≤502 ≤ N ≤ 50). Each of the following NN lines contains NN integers K_i,jK\_{i,j}, the number of pearls in the box in row ii and column jj (0≤K_i,j≤1050 ≤ K\_{i,j} ≤ 10^5, for 1≤i≤N1 ≤ i ≤ N and 1≤j≤N1 ≤ j ≤ N). In the input, the rows are given from top to bottom, and the columns are given from left to right.

Your program should output a single line containing only one integer RR (which can be 00, 11, 22, or 33), the smallest number of times the jewelry case must be rotated counterclockwise to return to its original state.

예제3

  1. 예제 1

    입력
    4
    15 9 7 3
    16 14 10 4
    20 17 11 6
    25 22 19 12
    
    예상 출력
    1
    
  2. 예제 2

    입력
    3
    300 250 150
    280 200 140
    240 190 130
    
    예상 출력
    2
    
  3. 예제 3

    입력
    2
    2 4
    1 3
    
    예상 출력
    3