Hanpan home
Hanpan Studio home
Hanpan
·STUDIO
HanpanProblemsContestsSubmissionsRankingEvents
My problemsMy contests
StatementPlaySubmit codeLeaderboardTournamentFriendliesSubmissions
Challenge #1

Icebreaking

Participant time limit
5,000 ms
Memory limit
512 MB
Submissions
374
Participants
35
Difficulty
Bronze VBronze IIISilver IIIGold IIPlatinum IRan Bronze V, Maki (1) Bronze III, Maki (2) Silver III, Asta Gold II, Laplace Platinum I
On this page
  • Problem
  • Input
  • Example
  • Sample code

Problem

Two players play an ice-breaking game on a 9×99 \times 99×9 ice board.

The ice board consists of 1×11 \times 11×1 cells arranged in 999 rows and 999 columns. Rows are numbered from 000 to 888 from top to bottom, and columns are numbered from 000 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 in one of the following states: empty ice, a hole #, a cell taken by the first player a, or a cell taken by the second player b. Only empty ice can be selected. Holes and cells already taken by a player cannot be selected again.

The board has exactly 999 holes. Their positions are determined by the seed given for each match, and each hole is on a different cell. Both players receive the same board as input before the game starts.

Each of the 727272 empty ice cells other than the holes has a score of −2-2−2, −1-1−1, 000, 111, or 222 written on it. The ice scores are also determined by the seed. Taking ice with a negative score can lower your total score.

The game starts with the first player A, and A and B take turns alternately. On your turn, you select one currently empty ice cell (r,c)(r,c)(r,c).

When a player selects an empty ice cell, the following steps happen in order.

  • The current player takes the selected cell and gains the score written on it.
  • Consider the region of empty ice, connected up, down, left, and right, that the cell belonged to just before it was selected.
  • If the region splits into two or more parts once the selected cell is gone, compare the sizes of the connected components.
  • The largest connected components remain as they are, and all smaller connected components become the current player's cells. This is called a chain capture.
  • The scores written on all chain-captured cells are added to the current player's total score.

Connectivity of empty ice is determined using only the four directions up, down, left, and right. Cells that touch only diagonally are not connected. Holes and taken cells are not part of any connected region of empty ice.

If several connected components share the largest size, all of them remain. If all the split components have the same size, no cells are chain-captured.

For example, if one region of empty ice splits into three regions of sizes 121212, 555, and 555, both regions of size 555 are chain-captured. If it splits into three regions of sizes 777, 777, and 333, only the region of size 333 is chain-captured.

The following actions are invalid.

  • Producing output that does not match the output format
  • Outputting coordinates outside the board
  • Selecting a hole or a cell that is already taken

A player who makes an invalid action loses immediately.

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

  • No selectable empty ice remains

  • A player makes an invalid action

  • A player exceeds the time limit or has a runtime error

Design an AI that becomes the final winner by considering both the board's connectivity and the score of each cell!

Input

Before the game starts, the judge gives both players the same initial board as the following 999 lines.

cell_0,0 cell_0,1 ... cell_0,8
...
cell_8,0 cell_8,1 ... cell_8,8

Each line contains the 999 cells of that row, separated by spaces.

  • If (r,c)(r,c)(r,c) is an ice cell, cell_r,c is the score of that cell, one of -2, -1, 0, 1, 2.
  • If (r,c)(r,c)(r,c) is a hole, cell_r,c is #.
  • Of the 818181 tokens in total, exactly 999 are #, and the remaining 727272 tokens are ice scores.
  • Hole positions and ice scores are determined by the match seed. Both players always receive the same initial board.

Once the initial state has been sent, the command exchange begins.

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

Command Judge→Player (input) Player→Judge (output) Time limit (ms) Description
READY READY (FIRST | SECOND) OK That player's remaining total time Tells the player whether they move first or second. FIRST is the first player A, and SECOND is the second player B. Time spent on the response is deducted from that player's total time.
TURN TURN my_time opp_time MOVE r c my_time Gives your remaining total time and the opponent's remaining total time. Output the coordinates (r,c)(r,c)(r,c) of the empty ice cell you select this turn. Time spent on the response is deducted only from your total time.
OPP OPP r c time - - Gives the legal coordinates the opponent just selected and the time they used.
FINISH FINISH - - Announces the end of the game. The player must exit the program normally without any further output.
  • r, c, my_time, opp_time, and time are integers.
  • r and c are between 000 and 888 inclusive and denote the row and column, respectively.
  • my_time, opp_time, and time are given in milliseconds.
  • Each player has their own independent total of 5,000ms5{,}000\text{ms}5,000ms. Time used by one player does not reduce the opponent's remaining time.
  • Response time for READY and all of your TURN responses is cumulatively deducted from your total time. There is no separate fixed time limit per turn.
  • Cumulative CPU time over the program's entire lifetime is also limited to 5,000ms5{,}000\text{ms}5,000ms per player. Startup processing, background computation during the opponent's turn, and computation in child processes all count toward this CPU total.
  • You must apply your own MOVE and the opponent's OPP under the same game rules to update the board and scores inside your program.
  • The r and c given by OPP are always the legal coordinates the opponent just selected.
  • After every output, print a newline and then flush the buffer.
  • Print debug messages only to standard error. Do not print anything other than protocol responses to standard output.
  • If you fail to respond within your remaining total time or use up the cumulative CPU total, you receive a time limit exceeded (TLE) verdict.
  • Printing a string that does not match the output format, or printing illegal coordinates in response to a TURN command, counts as an invalid action, and you lose immediately. After an invalid action, the opponent receives neither OPP nor the next TURN.

Example

After receiving the 999 lines of the initial board, communication can proceed as follows. The table below omits the initial 999 lines.

First player input First player output Second player input Second player output
READY FIRST READY SECOND
OK OK
TURN 4995 4996
MOVE 0 0
OPP 0 0 12
TURN 4996 4983
MOVE 8 8
OPP 8 8 9
TURN 4983 4987
MOVE 0 1
⋯\cdots⋯ ⋯\cdots⋯ ⋯\cdots⋯ ⋯\cdots⋯
FINISH FINISH

Sample code

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

Author

  • lll
    Bronze Vlll
  • swoon
    Bronze Vswoon
  • wapas
    Silver Iwapas
PlaySubmit code
© 2026 hanpan
Privacy Policy

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