<PREV Problem:
NEXT>
Solved by 240 users: ...
UserDateAttemptTimeCMSC
Abzal_ktl27 dec 2007Kylix100.01238 
LOD24 may 2017C++100.01301 
fetetriste01 may 2008C++700.01407 
Fenriz09 aug 2004FPC3?.??410 
checkil12 dec 2008C++100.01431 
Nikol12 dec 2008C++200.01431 
Oleg4225 dec 2010C++100.01441 
oleg.dudrov15 jan 2011C++100.01441 
Vladislav_Simonenko05 oct 2006C++200.01445 
registration25 dec 2007C++300.01453 
Languages
C++
136
FPC
60
Kylix
16
C
14
Java
13
Ruby
1
 > 
 > 
 > 
 > 
 > 
 > 
 > 
 > 
 > 
 > 

Bridges

Time limit = 5 seconds

The Game "Bridges" is one of the strategic games in which the human mind bits the computer. Human mind is familiar with side-tracks, reserve ways, ruses and tricks. Human mind is a wild card, what can't be said about computer — it does what it is programmed to do and nothing more.

We have square game field N × N, where N is odd.

Each cell has color, white, red or blue, and coordinates (x, y), x = 1, 2, ... N, y = 1, 2,..., N.

At the beginning cells with odd x and y, and cells with even x and y are white. Others are red or blue. See figure.

"Red player" begins and colors one of the white cells to red. Then "Blue player" moves — colors one of white cells to blue. They make moves in turn. "Red player" should build red bridge from left to rigth side of the square. "Blue player" — blue bridge from top to bottom side.

Try yourself here.

You are given description of game field after some moves made.

Write program which can determine "one move to bridges" and "two moves to bridge" positions.

Position is "one move to bridge" if the player whose turn can make move and build bridge.

Position is "two moves to bridge" if after any move of the player whose turn the second player will have possibility to move and build bridge.

Whose turn is can be determined by the number of blue and red cells.

Input. The first line has number N. Next N lines have N characters each. These characters are 'R', 'B' or '.'.

Output. Output 1 if "one move to bridge". Output 2 if "two moves to bridge". Output 0 if these are not cases.

Input#1
3
.B.
R.R
.B.
Output#1
1

Input#2
7
.B.BBB.
RBR.RRR
.B.B.B.
RRRRR.R
.B.B.B.
R.R.R.R
.B.B.B.

Output#2
2

Input#3
7
.B.B.B.
R.R.R.R
.B.B.B.
R.R.R.R
.B.B.B.
R.R.R.R
.B.B.B.
Output#3
0

Author:
Voroztsov Artem, MIPT Contest, February 2003
16 Fabruary 2003

<PREV | Problem set | Search related messages | NEXT>


© acm.mipt DevGroup
The page was generated in 210ms

SW soft NIX
ID = 3.214.184.250