Vox in Box

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 0.6s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
2015 Mock CCC by Alex and Timothy

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 \le N \le 1\,000). 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, or 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^{\circ} 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 to themselves in all 4 directions.
  • The characters ( and ) are symmetrical to themselves horizontally, symmetrical to each other vertically, and are asymmetrical diagonally.
  • 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 be one integer, the number of lines of symmetry.

Sample Input 1


Sample Output 1


Explanation for Sample 1

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

Sample Input 2


Sample Output 2


Sample Input 3


Sample Output 3



  • 1
    BMP  commented on May 23, 2015, 1:17 p.m.

    "characters ( and ) are symmetrical to themselves horizontally"

    isn't it supposed to be 'to each other'

    • 5
      lolzballs  commented on May 24, 2015, 6:16 p.m.

      I believe that it is correct, as a horizontal line is this ("-----------------") way. "(" reflected on that line is itself hence it is symmetrical to itself horizontally. The same applies to ")".

      • 4
        BMP  commented on May 24, 2015, 8:50 p.m.

        Thanks! I love you balls!

      • 1
        bobhob314  commented on May 24, 2015, 6:21 p.m.

        Yeah we figured this out yesterday too. Thanks lolzballs!

    • 1
      bobhob314  commented on May 23, 2015, 4:24 p.m.

      I think you're right...