Tetris
题号:NC15843
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 32 M,其他语言64 M
64bit IO Format: %lld

题目描述

Tetrisis a typical game, and Small Small Blue loves to play it very much.

Tetriminos are game pieces shaped like tetrominoes, geometric shapes composed of four square blocks each. A random sequence of Tetriminos fall down from the top of the playing field (a rectangular vertical shaft, called the "well" or "matrix"). The objective of the game is to manipulate these Tetriminos, by moving each one sideways (if the player feels the need) and rotating it by 90 degree units, with the aim of creating a horizontal line of ten units without gaps. When such a line is created, it gets destroyed, and any block above the deleted line will fall. The game ends when the stack of Tetriminos reaches the top of the playing field and no new Tetriminos are able to enter.
                                            
                                                                            7 type of Tetriminos
                                                        

Small Small Blue is playing tetris on a N*M playing field and we use ‘o’ and ‘x’ to describe it. ‘o’ means the cell is empty and ‘x’ means the cell is occupied. He know what kind of Tetriminos will falling down next, he wonder the minimal number of occupied lines. If the new Tetrimino is unable to enter, please output “Game Over!”.


输入描述:

There are multiple test cases (at most 25 groups) in the input.
The first line of input contains two integers x,y (1 ≤x,y≤ 4).
Then follow x lines, each line consists of y characters that describe the Tetriminos falling down next.
The x+1 line of input contains two integers n,m (1 ≤n,m≤ 3000).
Then follow n lines, each line consists of m characters that describe the current playing field.
All the characters are either ‘o’ or ‘x’.

输出描述:

For each test case, please output a line containing the minimum number of occupied lines or “Game Over!”.
示例1

输入

复制
2 3
xoo
xxx
10 10
oooooooooo
oooooooooo
oooooooooo
oooooooooo
oooooooooo
oooooooooo
oooooooooo
oooooooooo
xxoxooxxxx
ooxxxxxxxx
1 4
xxxx
10 10
oooooooooo
oooooooooo
oooooooooo
oooooooooo
oooooooooo
oooooooooo
oooooooooo
xoooooxoox
xxoxxxooox
xxooxoooox

输出

复制
3
3