Lagno
InterviewTime limit1sMemory limit128 MB
Count the most white pieces a single black move flips on an 8 by 8 Othello board.
- Level
Easy3 of 10
- Topics
- Simulation, Matrix, Brute force
- Solved
- No attempts yet
Problem
Lagno (also known as Reversi and Othello) is a board game for two players, black and white. The board is a square made of 8 rows and 8 columns.
In one move, the black player places a black piece on an empty square such that, in at least one of the eight directions (up, down, left, right, and the four diagonals), the segment between the newly placed piece and some already-present black piece is filled by an unbroken line of one or more white pieces. After the piece is placed, every white piece caught this way between the new black piece and a pre-existing black piece (in each such direction) turns black.
Given a board layout, write a program that computes the largest number of white pieces the black player can convert in a single move.
Input
The input consists of eight lines, each containing exactly eight characters '.', 'B', or 'W'. The character '.' is an empty square, 'B' is a square holding a black piece, and 'W' is a square holding a white piece.
Output
Print the largest number of white pieces black can convert in a single move. If there is no legal move, print 0.