Lines of X

시간 제한3초메모리 제한2048 MB

요약
N x N 격자의 빈 칸을 X 또는 O로 채워서 행, 열, 대각선 중 적어도 하나가 모두 X가 되는 경우의 수를 구한다.
난이도

보통10점 중 5점

유형
백트래킹, 비트 연산, 완전 탐색, 조합론
정답자
아직 제출이 없습니다

문제

Tic-tac-toe is boring. The optimal strategy is simple to work out. But what about a generalization to an N×NN \times N board. That also does not seem interesting, and you probably won’t convince anyone to play with you. So you decide to have your own fun with such grids.

Given a N×NN \times N grid GG where each cell contains a single X, O, or . (the latter meaning the space is empty), you want to calculate the number of ways one can fill out the empty cells in GG so that there is at least one line that is all X. The lines of the grid are the NN rows, the NN columns, and the 22 diagonals.

More precisely, compute the number of N×NN \times N grids HH that have the following properties:

  • HH contains only X or O entries, no empty cells.
  • The only cells where GG and HH can differ is at the empty cells in GG.
  • At least one row, column, or diagonal line of HH only contains X.

입력

The first line of input contains a single integer NN (2≤N≤82≤N≤8) indicating the dimensions of the grid. The next NN lines describe the rows of the grid, each row is a string of length exactly NN containing only characters ., O, X.

출력

Output a single number indicating the number of ways to fill out the . characters in the grid with either O or X so that the resulting grid has at least one line with all characters being X.

예제4

  1. 예제 1

    입력
    2
    X.
    ..
    
    예상 출력
    7
    
  2. 예제 2

    입력
    2
    X.
    .O
    
    예상 출력
    3
    
  3. 예제 3

    입력
    3
    XO.
    O.X
    OXO
    
    예상 출력
    0
    
  4. 예제 4

    입력
    2
    XX
    XX
    
    예상 출력
    1