A Very Long Hike
시간 제한6초메모리 제한2048 MB
n x n 고도 행렬이 평면을 주기적으로 채울 때, 한 걸음 비용이 1에 고도 차를 더한 값일 때 1e20초 안에 도달할 수 있는 서로 다른 격자점의 수를 센다.
문제
You are planning a hike in the Peneda-Gerês National Park in the north of Portugal. The park takes its name from two of its highest peaks: Peneda (1340 m) and Gerês (1545 m).
For this problem, the park is modelled as an infinite plane, where each position , with , being integers, has a specific altitude. The altitudes are defined by an matrix , which repeats periodically across the plane. Specifically, for any integers , and , the altitude at is .
When you are at position , you can move to any of the four adjacent positions: , , , or . The time required to move between two adjacent positions is , where and are the altitudes of the current and destination positions, respectively.
Initially, your position is . Compute the number of distinct positions you can reach within seconds. Your answer will be considered correct if its relative error is less than .
입력
The first line contains an integer ()—the size of the matrix describing the altitudes.
The following lines contain integers each. The -th number on the -th of these lines is ()—the altitude of the position .
출력
Print the number of distinct positions you can reach within seconds. Your answer will be considered correct if its relative error is less than .