시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 1024 MB | 1 | 1 | 1 | 100.000% |
Chaos City has grown out of control. Building have been built everywhere and the city layout is a complete mess. The mayor decided that this must come to an end, and wants to create a nice, structured city.
After some research, he found the ideal way to make this happen. Inspired by the New York district of Manhattan, he wants all buildings organized in a rectangular grid, separated by avenues running from North to South and streets running from West to East. These streets and avenues should all be separated by the same distance D.
In the current situation, the buildings are already organized in a rectangular grid. In fact each buildings fills exactly one square in this grid. However, with all the buildings randomly scattered across the city, it may be impossible to build the roads without demolishing a couple of buildings. To keep most citizens happy, the mayor wants to demolish as few buildings as possible. Given the current locations of the buildings, what's this minimum number?
The above picture illustrates the problem. The shaded squares are the initial locations of the buildings. If the roads should be separated by a distance of three, the thick lines indicate the optimal placement of the roads and one building has to be demolished.
The first line of the input contains a single number: the number of test cases to follow. Each test case has the following format:
For every testcase in the input, the output should contains a single line with the minimum number of buildings that has to be demolished.
1 3 10 1 0 2 0 3 0 4 0 1 2 0 3 1 5 3 5 4 2 -2 2
1