2015 Mock CCC by Alex and Timothy

Problem J4: Vox in Box

Michiru has an interesting Volvox colony which she keeps in a square open-air box (to allow them to photosynthesize). The base of the box is a square with a side length of N units (1 ≤ N ≤ 1000). One day, she took a picture of it and printed out an ASCII image of the colony. The image is made of the characters ., O, (, ), /, and \. Since Michiru is an inquisitive girl, she would like to know how many lines of symmetry there are in her Volvox colony.

A line of symmetry can be one of 4 types of lines – either a horizontal line, a vertical line, a diagonal line running top-left to bottom-right, and a diagonal line running top-right to bottom-left. The horizontal and vertical lines must be parallel to sides of the box, while the diagonal lines must be at 45° angles relative to the sides. Furthermore, a line of symmetry should divide the ASCII image into two halves of equal area which are symmetrical to each other with respect to that line.

For individual characters on the ASCII image, Michiru has observed that:

  • The characters . and O are symmetrical in all 4 directions.
  • The characters ( and ) are symmetrical to themselves horizontally, and symmetrical to each other vertically.
  • The characters / and \ are symmetrical to themselves diagonally, and symmetrical to each other both vertically and horizontally.

Please help Michiru count the number of lines of symmetry.

Input Format

Line 1 of input will contain a single integer N, the side length of the box.
The next N lines will each have N characters, depicting an ASCII image of the Volvox colony.

Output Format

The output should consist of a single integer, the number of lines of symmetry.

Sample Input 1

5
.....
.....
.(O).
.....
.....

Sample Output 1

2

Explanation of Sample 1

The Volvox is symmetrical horizontally and vertically, but not diagonally.

Sample Input 2

5
/...\
..O..
.OOO.
..O..
\.../

Sample Output 2

4

Sample Input 3

6
..\/..
\(OO)/
(OOOO)
(OOOO)
/(OO)\
../\..

Sample Output 3

2

All Submissions
Best Solutions


Point Value: 7
Time Limit: 1.00s
Memory Limit: 64M
Added: Feb 18, 2015
Authors: FatalEagle, Alex

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

It's quiet in here...