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 units wide and
units high. Contrary to TETRIS, t-pieces cannot
be rotated. Moreover, they cannot be moved to the left or right after they start
falling. Thus, for each t-piece the player must only choose the container's column
number (integer from
to
) where the leftmost square of the piece (marked as
)
will fall.
Each game consists of a finite sequence of t-pieces from which as many as
possible must be dropped in the container without exceeding its upper level or
making an illegal move. The score of the game is equal to the number of successfully
dropped t-pieces.
At the beginning the game counter is set to
.
The algorithm of the game is the following:
- 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 t-pieces is the following:
. Let's assume
that the first
t-pieces have already been
successfully dropped in the container in the columns
,
respectively. Until this moment no lines have been completed, the current value of
the counter is
and it is time to drop t-piece
(letters in the figure are assigned
consecutively to t-pieces):
There are only two valid columns where t-piece can be dropped:
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 . The next
lines
describe the t-piece sequence; each line contains an integer between
and
- the
number of the particular t-piece. T-pieces are given in the order how they must be
dropped in the container; the
-th t-piece is given in the
-st line of the file.
Output Specification
For each of the given input files, you must output at most rows - the numbers of
the columns where pieces are dropped. The
-th row of the output file must contain
the number of the column where the
-th t-piece from the input data must be
dropped.
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 points. The amount of points you will
receive for a particular output file (test case) is calculated using the following
formula:
rounded to the nearest integer.
Comments