WC '01 Suicidal P1 - Survivor

View as PDF

Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 16M

Problem type
Woburn Challenge 2001 - Suicidal

This is the first day of orientation and the frosh are already ready to isolate themselves. Therefore, they have been divided into 2 groups or "tribes" (and never the two shall meet). The two tribes are called the Keeg and the Dren. The orientation leaders have divided the barren wasteland that is the city of Waterloo into a giant grid; both tribes are to compete in a contest on this grid.

To begin the game, a random number will be drawn from a hat to represent the number of turns that will take place before the game is declared over. During each turn, each tribe will alternately position one of their students at one of the grid positions.

The goal is as follows. If you draw a straight line between students of the same tribe, it might turn out that 4 students are positioned so that they form a square (not necessarily parallel to the grid axis). On the last turn, the object of each tribe is to position a student of your tribe on the grid so that the square of largest possible area is formed using the students of that tribe on the grid as vertices of the square (the area is calculated from the coordinates of the square).

The tribe that forms that largest area wins and the losing tribe is kicked off the island (translation: kicked out of Waterloo engineering). Note that this event has been approved by Waterloo faculty as a much more efficient method of weeding out students from first year engineering.

Input Specification

N (the size of the square grid, N \le 60; N = -1 signals the end of input)

The next N lines represent the grid itself at the beginning of the last turn: * means an unoccupied grid position, k represents a Keeg student, d represents a Dren student.

The next line of input is either k or d. You must place a student of the appropriate tribe (depending on whether the input is k or d) on a position on the grid to come up with the square of maximum area.

Output Specification

The area of the largest such square that can be formed by the addition of the last student of the appropriate tribe.

Sample Input

4
*k**
**k*
*k*d
**d*
k
-1

Sample Output

2

NOTE: this is obtained by placing k at row 2, column 1; \text{area} = (\sqrt 2)^2 = 2


Comments

There are no comments at the moment.