TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

John and Brus have become very famous people all over the world, especially in Bolivia. Once they decided to visit their fan club in Bolivia. John has an old map of Bolivia which shows all of its cities and the roads connecting them. All roads are bidirectional, meaning they can be traversed in both directions. Since the map is old, it's possible that some additional roads have been built since the map was produced. However, roads are never destroyed in Bolivia, so all the roads on the map still exist.


Brus has discovered on the Internet that each pair of Bolivian cities now has at least one and at most two simple paths connecting them. A path between cities A and B is a sequence of cities starting with A and ending with B such that there's a road between each pair of consecutive cities in the sequence. The path is considered simple if it consists of distinct cities.


John and Brus have decided to add some new roads to the old map in such a way that the resulting map satisfies this condition. They can only add a road between a pair of cities if that road did not already exist in the old map. They can't add more than one road between the same pair of cities, and they can't add a road that leads from a city to itself. All added roads must be bidirectional.


You are given some maps. The j-th character of the i-th row of map will be 'Y' if there is a road between the i-th and j-th cities on the old map, or 'N' otherwise. Return the number of ways John and Brus can add new roads to the old map modulo 1234567891. Two ways are considered different if the sets of added roads are distinct. The order in which roads are added does not matter.

Input Format

Please see sample I/O.

  • 1<=n<=20
  • Each row of map will contain exactly n characters, where n is the number of row in map.
  • Each character of map will be either 'Y' of 'N'.
  • The j-th character of the i-th row of map will be equal to the j-th character of the i-th row of map.
  • The i-th character of the i-th row of map will be 'N'.
  • There will be at least one way for John and Brus to add new roads to the old map.

Output Format

Please see sample I/O.

Sample Input 1

2
NN
NN
3
NNY
NNN
YNN
2
NY
YN
4
NYNN
YNNN
NNNY
NNYN
12
NNNNNNNNNNNN
NNNNNNNNNNNN
NNNNNNNNNNNN
NNNNNNNNNNNN
NNNNNNNNNNNN
NNNNNNNNNNNN
NNNNNNNNNNNN
NNNNNNNNNNNN
NNNNNNNNNNNN
NNNNNNNNNNNN
NNNNNNNNNNNN
NNNNNNNNNNNN
1
N
5
NYYNN
YNYNN
YYNNN
NNNNY
NNNYN

Sample Output 1

1
3
1
10
1137797187
1
6

Hints

Problem Source

Migrated from old NTUJ.

Topcoder SRM 460 round 1

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 10000 65536 200