시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 512 MB 4 3 3 75.000%

문제

As you may know, the popular computer game “Tetris” was invented by Russian programmer Alexey Pajitnov. In this problem you need to write program which plays a simplified version of this game.

The playing field is a rectangular vertical shaft, called the “well”. Random figures of unit square blocks appear on top of the wall, the player chooses the horizontal position and rotation of the figure, after that the figure falls down in the well. The objective of the game is to create horizontal lines filled without gaps. When such a line is created, it disappears, and any blocks above the deleted line fall.

In this version of the game, the well size units, and there are only three types of figures:

Type Figure
1
2
3

You lose if at some point there are five non-empty lines of the well. You win if you hadn't lost after n figures have fallen.

You need to write program which plays the game described above and wins regardless of which figures will appear.

구현

You should implement four functions (methods):

  • void init(int n). This function is called before any other function.
  • void new_figure(int figure_type). This function is called when a new figure appears. figure_type is a number from 1 to 3, indicating the type of the figure according to the table above.
  • int get_position(). This function should return a number from 0 to 2, the position of the leftmost block of the last figure.
  • int get_rotation(). This function should return a number from 0 to 3, the number of time the figure was rotated couter-clockwise.

Functions get_position and get_rotation will be called only after new_figure.

예제

The grader makes the following function calls:

  • init(3). There will be three figures.
  • new_figure(1). A figure of type 1 falls from the top of the well.
  • get_position() returns 0. This means that player wants to put the figure in the leftmost column.
  • get_rotation() returns 1 (or 3). This means that player wants to rotate the figure vertically.
  • After the figure has fallen, the well looks like this:

  • new_figure(3).
  • get_position() returns 1.
  • get_rotation() returns 1.
  • After the figure has fallen, the first line is full, so it disappears and the well looks like this:

  • new_figure(2).
  • get_position() returns 1.
  • get_rotation() returns 0 (or 2).
  • After the figure has fallen, the second line is full, so it disappears and the well looks like this:

제한

In all subtasks n ≤ 1000.

서브태스크

번호 배점 조건
1 7

All figures have type 1.

2 8

All figures have type 2.

3 10

All figures have type 1 or 2.

4 21

All figures have type 3.

5 54

Figures can have different types.

샘플 그레이더

The sample grader reads the input in the following format:

  • Line 1: One integer n.
  • Line 2: n integers: types of figures.

제출할 수 있는 언어

C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)

채점 및 기타 정보

  • 예제는 채점하지 않는다.