Baltic Olympiad in Informatics: 2012 Day 2, Problem 3
Elder people still remember the famous computer game "TETRIS" created by Alexey Pajitnov, where pieces consisting of four squares (tetrominoes) fall from the sky and the goal of the game is to rotate and land every piece in a rectangular container creating as many lines of blocks without gaps as possible. When such lines are created, they disappear giving more space for the following pieces. Let's investigate a simpler version of the game, called "Tiny TETRIS" (or just "Tiny" for short). There are only nine different Tiny pieces (or t-pieces) consisting of one to three squares:
The number denotes the type of a t-piece and will be used further to reference
the particular t-piece.
The goal of the game is the same - falling t-pieces must be put in a rectangular
container which is
Each game consists of a finite sequence of
- Player chooses the column for the leftmost square of the current t-piece;
- If the column is set correctly (for example, column
can never be correct for the t-piece ), t-piece falls down until it meets an obstacle; otherwise the game is over. - If the t-piece fully fits inside the container (i.e., all squares are inside the
rectangle) the value of the counter is increased by one. Otherwise, the game is over. - Then it is checked whether there are any completed horizontal lines (horizontal lines filled completely with blocks of t-pieces without any gaps). If there are any then these lines disappear and the lines above them are shifted down without changing their configuration.
- If there are any t-pieces left, proceed to step
. Otherwise the game is over.
The score of a particular game is the value of the counter at the moment when the game ends. Let's analyze one particular game.
Sequence of the given
There are only two valid columns where t-piece
a) column |
b) column |
![]() |
![]() |
Input Specification
The problem has been adapted from its original format for DMOJ. Your program is given five files each containing a description of a particular game: tiny.i1
,
tiny.i2
, tiny.i3
, tiny.i4
, and tiny.i5
. They can be downloaded here for you to study: tiny.zip.
Each file contains the sequence of t-pieces and
has the following format: the first line contains a single integer
Output Specification
For each of the given input files, you must output at most
It is guaranteed that for each input file there exists a sequence of columns which
allows all t-pieces to be successfully dropped in the container (and gets the final
score for the game equal to
Grading
Each of the five test cases is worth
rounded to the nearest integer.
Comments