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

Maki's Candy Hunt

Participant time limit
1,000 ms
Memory limit
512 MB
Submissions
143
Participants
7
On this page
  • Problem
  • Input
  • Example
  • Sample code

Problem

Candy is scattered across the corridors of Heurika Academy. Maki wants to collect as much candy as possible before getting caught by the tagger.

The corridors form a maze of NNN rows and NNN columns. NNN is an integer between 111111 and 232323 inclusive. Rows are numbered from top to bottom and columns from left to right, each from 111 to NNN, and the cell in row xxx and column yyy is denoted (x,y)(x,y)(x,y).

Each cell is either a wall or a passage. The outermost ring of cells is all passage, and Maki and one tagger start on different inner passages. Let FFF be the number of passages excluding the outermost ring. Then there are max⁡(1,min⁡(F−2,⌊0.2F+0.5⌋))\max(1,\min(F-2,\lfloor 0.2F+0.5\rfloor))max(1,min(F−2,⌊0.2F+0.5⌋)) candies. Initially, the candies are placed on different passages that hold neither Maki nor the tagger, and they may also be placed on the outer passages.

Maki cannot see the whole maze. The direction Maki initially faces is chosen at random from up, down, left, and right, and Maki sees the surroundings as follows.

  • On Maki's own cell and straight ahead up to the first wall, Maki sees the terrain, candy, and the tagger. This includes the first wall, and if there is no wall, Maki sees to the edge of the maze.
  • For the cells directly to Maki's left, right, and back, Maki only knows whether each is a wall or a passage. For the cells directly to the left and right of each passage cell visible ahead, Maki also knows only the terrain.
  • Maki cannot see the cells on either side of the first wall or anything beyond the wall. The view does not bend along passages that branch off to the side either.

Here, left and right are relative to the direction Maki is facing. The figure below shows Maki at (5,5)(5,5)(5,5) facing up.

Maki's forward view and the side cells where only terrain is visible

Maki remembers terrain and candy once they have been seen. Maki knows from the start that the outer ring is passage, but has to see it directly to know whether there is candy there. The map given each turn shows the current view and everything remembered so far with the following symbols.

Symbol Meaning
? Cell not known yet
# Known wall
. Known passage
P Maki's current position
C Known candy
H Tagger currently in view
X Cell holding both the tagger currently in view and candy

Candy does not move or disappear until Maki eats it. Candy that has been seen stays marked as C even when it is out of view. Cells where only terrain is seen keep their previous candy information. The tagger is shown as H or X only while it is in the current view. . means a known passage, and outside the view it may hold newly placed candy or the tagger. You also cannot tell from # and . alone whether a cell is in the current view.

Candy that stays marked out of view, and the tagger that is not shown

Maki can also hear the tagger's footsteps. The following value is given based on the shortest distance between the two characters, moving up, down, left, and right without passing through walls. Footsteps do not reveal the tagger's direction.

Shortest distance Footsteps
666 or more cells 000
444 to 555 cells 111
222 to 333 cells 222
111 cell 333

On each turn, Maki performs one of the following actions. Every action uses one turn.

Action Description
U Face up and move one cell.
D Face down and move one cell.
L Face left and move one cell.
R Face right and move one cell.
O Look around in all four directions without moving.
S Wait in place.

If the target cell is a wall or outside the maze, only the facing direction changes and Maki does not move. This still uses one turn. O and S do not change the position or the final facing direction.

Moving into a wall keeps the position and changes only the facing direction

When Maki performs O, Maki sees the combined view of facing each of the four directions. For cells whose contents are visible from at least one direction, Maki checks candy and the tagger as well, and for all other cells Maki checks only the terrain. What is seen at this point is immediately added to memory. After the tagger moves, only the view in the direction Maki was originally facing is checked again. The next input shows only the tagger visible at that time.

The view at the moment of looking around and in the next input

A turn proceeds in the following order.

  1. Maki acts. On arriving at a cell with candy, Maki eats it and earns 111 point.
  2. The eaten candy is immediately placed again on another passage that has no Maki, tagger, or other candy. It may also be placed on an outer passage, and the total number of candies stays the same.
  3. The view right after Maki's action is added to memory. If Maki and the tagger are on the same cell, Maki is caught and the game ends.
  4. The tagger acts once on odd-numbered turns and twice on even-numbered turns. If the two characters are on the same cell right after any of these actions, the game ends immediately.
  5. If the game has not ended, Maki's normal view and the footsteps are updated, and play moves on to the next turn.

The tagger also uses moving up, down, left, and right, looking around, and waiting.

The tagger does not eat candy and can stand on a cell with candy. If Maki moves onto a cell that holds both the tagger and candy, Maki earns the point for the candy and is then caught. Since Maki is caught as soon as both are on the same cell, the two characters cannot pass through each other or swap places.

The game ends when Maki is caught or when the tagger's actions on turn 100100100 are finished. The score of a game is the number of candies eaten. Points already earned are kept even if Maki is caught.

Design an AI for Maki that avoids the tagger and collects as much candy as possible!

Input

The judge communicates with the player as follows. Values on each line are separated by spaces.

Command Judge → Player (input) Player → Judge (output) Time limit (ms) Description
READY READY N d OK 1000 Gives the size of the maze and the initial facing direction.
TURN TURN remaining_ms a Gives the remaining response time and the footstep level.
row1
...
rowN One of U, D, L, R, O, S remaining_ms After reading the NNN lines of the map, output one action.
FINISH FINISH None None Exit the program.
  • N is the size of the maze, an integer with 11≤N≤2311 \le N \le 2311≤N≤23.
  • d is the initial facing direction, one of U, R, D, L.
  • a is the footstep level, an integer between 000 and 333 inclusive.
  • row1 through rowN are the rows of the map. Each line is a string of length NNN, and each character is one of ?, #, ., P, C, H, X. The meaning of each character is the same as in the problem statement.
  • remaining_ms is the response time remaining for the game, an integer in milliseconds.
  • After every output, print a newline and then flush the buffer.

Example

This is the first turn from a recorded run of the example program.

Judge → Player (input) Player → Judge (output)
READY 12 U
OK
TURN 999 0
............
.??????????.
.??????????.
.??????????.
.??????????.
.??????????.
.??????#???.
.?????#P#??.
.??????.???.
.??????????.
.??????????.
............
L
... ...
FINISH

Sample code

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

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.