import java.io.PrintStream; import java.util.Arrays; import java.util.Scanner; /** * Solution to MazeMan. * * @author vanb */ public class mazeman_vanb { /** Input. */ private static Scanner sc; /** Output. */ private static PrintStream ps; /** The maze. */ private char maze[][]; /** The count of dots. */ private int dots = 0; /** * Traverse the maze. * * @param i the i coordinate * @param j the j coordinate * @return true, if dots were eaten */ private boolean traverse( int i, int j ) { boolean gotDots = false; // Can we go here? if( i>=0 && i=0 && j='A' && maze[i][0]<='W' ) if( traverse( i, 1 ) ) ++exits; // Right if( maze[i][m-1]>='A' && maze[i][m-1]<='W' ) if( traverse( i, m-2 ) ) ++exits; } // Go along the horizontal walls for( int j=0; j='A' && maze[0][j]<='W' ) if( traverse( 1, j ) ) ++exits; // Bottom if( maze[n-1][j]>='A' && maze[n-1][j]<='W' ) if( traverse( n-2, j ) ) ++exits; } ps.println( exits + " " + dots ); } /** * Main. * * @param args unused * @throws Exception the exception */ public static void main( String[] args ) throws Exception { sc = new Scanner( System.in ); ps = System.out; new mazeman_vanb().doit(); } }