Hanpan home
Hanpan Studio home
Hanpan
·STUDIO
HanpanProblemsContestsSubmissionsRankingEvents
My problemsMy contests
StatementPlaySubmit codeLeaderboardSubmissions
Challenge #2

Hanpang

Participant time limit
5,000 ms
Memory limit
512 MB
Submissions
305
Participants
23
On this page
  • Problem
  • Input
  • Example
  • Sample code

Problem

Hanpang is a single-player game on a 15×815 \times 815×8 board in which you clear same-colored tiles all at once to earn a high score.

1. Board and Tiles

The board consists of 1×11 \times 11×1 cells arranged in 151515 rows and 888 columns. Rows are numbered from 111 to 151515 from top to bottom, and columns are numbered from 111 to 888 from left to right. The cell in row rrr and column ccc is denoted (r,c)(r,c)(r,c).

Each cell is either empty or holds a tile of one of three colors. The color of each newly created tile is chosen from the three colors independently and with equal probability.

At the start of the game the board is empty, and one row of 888 new tiles is added at the bottom.

2. Gameplay

In each turn, you select one non-empty cell (r,c)(r,c)(r,c). The selected tile and all same-colored tiles connected to it up, down, left, and right are removed. Tiles that touch only diagonally are not connected, and you may select a tile even if it is the only tile in its connected group.

Removing kkk tiles at once earns k2k^2k2 points. After the removal, the remaining tiles in each column fall down so that no empty cells are left between them.

Then a row of 888 new tiles is added at the bottom of the board, and the existing board shifts up by one row. This whole process makes up one turn.

3. Game End and Scoring

The game ends when any of the following conditions is met.

  • Adding a new row pushes a tile that was in the top row off the board
  • 200200200 turns have been played

Points earned by the last action that ended the game also count toward the final score. The final score is the sum of all points earned until the game ends.

Design an AI that builds large connected components and earns a high score while new rows keep being added!

Input

The judge communicates with the player one line at a time as follows.

Command Judge→Player (input) Player→Judge (output) Time limit (ms) Description
START START READY Remaining total time Announces the start of the game. Time spent on the response is deducted from the player's total time.
TURN TURN remaining_ms new_row PANG row col remaining_ms Gives the remaining time and the new row to be added. After the new row is added at the bottom of the board, output the coordinates (row,col)(row,col)(row,col) of the tile to remove.
  • remaining_ms, row, and col are integers.
  • remaining_ms is the player's remaining time in milliseconds.
  • new_row is a string of length 888, and each character is one of 1, 2, 3, indicating a tile color. The new_row given in the first TURN is also added as the bottom row of the board.
  • row is between 111 and 151515 inclusive and col is between 111 and 888 inclusive. They denote the row counted from the top and the column counted from the left, respectively.
  • The cell selected with PANG row col must contain a tile. A tile whose connected component has size 111 can also be selected.
  • The player may use a total of 5,000ms5{,}000\text{ms}5,000ms across the START response and all TURN responses.
  • After every output, print a newline and then flush the buffer.
  • If you fail to respond within the remaining time, the game ends and the last confirmed score is used as the final score.
  • If you print a string that does not match the output format or invalid coordinates, the game also ends, and the score confirmed just before that action is used as the final score.
  • When the game ends, the judge terminates the player's program without sending any further commands.

Example

The following is an example of communication between the player and the judge. Time values are for illustration only.

Judge→Player input Player→Judge output
START READY
TURN 5000 32131311 PANG 15 7
TURN 4999 11223312 PANG 15 7
⋮\vdots⋮ ⋮\vdots⋮

Sample code

  • PYTHON3, PYPY3 : main.py
  • CPP20 : main.cpp

Author

  • swoon
    Bronze Vswoon
PlaySubmit code
© 2026 hanpan
Privacy Policy

Tier icons are copyrighted by solved.ac. This service is not affiliated with solved.ac.