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

Sakura Duel

Participant time limit
1,000 ms
Memory limit
256 MB
Submissions
525
Participants
16
Difficulty
Gold IVGold IPlatinum IVMaki Gold IV, Asta Gold I, Laplace Platinum IV
On this page
  • Problem
  • Input
  • Example
  • Sample code

Problem

Two players fight a duel in a 7×77 \times 77×7 courtyard. You win by knocking your opponent down, pushing them out of the courtyard, or gathering blessings at the spirit vein.

Rows and columns are numbered from 111 to 777 from top to bottom and from left to right, respectively, and the cell in row rrr and column ccc is denoted (r,c)(r,c)(r,c).

The courtyard has one cell called the spirit vein, where blessings can be gained. The starting positions of both players and the position of the spirit vein are chosen at random for each match. The two players start on different cells, and the spirit vein stays in the same place throughout the match.

Each player starts with 101010 health and 000 blessings, and all techniques are available.

Example of an initial setup: Player 1 (4,3), Player 2 (4,5), spirit vein (2,4).

Example of an initial setup: Player 1 (4,3), Player 2 (4,5), spirit vein (2,4).

Turn Flow

The game lasts at most 606060 turns. Each turn, both players choose two actions in order ahead of time. Once both have chosen, the two first actions are resolved simultaneously, and then the two second actions are resolved simultaneously. If the outcome is decided while actions are being resolved, the game ends immediately.

A player standing on the spirit vein after both actions gains 111 blessing. Blessings accumulate.

Ending the turn on the spirit vein with Move right → Wait gains 1 blessing.

Ending the turn on the spirit vein with Move right → Wait gains 1 blessing.

Actions

Choose a direction from up, down, left, and right. Flash Step can also use the four diagonal directions. Front means the chosen direction.

Action Effect Cooldown (turns)
Wait icon Wait Does nothing. 000
Move icon Move Moves one cell in the chosen direction. 000
Thrust icon Thrust Attacks the first and second cells in front, dealing 222 damage. 111
Sweep icon Sweep Attacks the three cells in front and the two cells on either side of you, dealing 222 damage and pushing the opponent one cell in the chosen direction. 222
Charge icon Charge Moves one cell, then attacks the first and second cells in front, dealing 333 damage and pushing the opponent two cells in the chosen direction. 222
Guard icon Guard Blocks attacks from an opponent in the three cells in front or in the second cell in front. 222
Shatter icon Shatter Attacks the first cell in front. Ignores Guard, deals 222 damage, and pushes the opponent one cell in the chosen direction. 111
Flash Step icon Flash Step Moves exactly two cells in the chosen direction, passing through an opponent in the middle cell. 222

Attack and Guard ranges apply only to cells inside the courtyard.

Thrust ↑

Thrust Thrust icon

Sweep ↑

Sweep Sweep icon

Charge ↑

Charge Charge icon

Guard ↑

Guard Guard icon

Shatter ↑

Shatter Shatter icon

Flash Step ↑

Flash Step Flash Step icon

The six actions other than Wait and Move are called techniques. A technique can be chosen only if it is available at the start of the turn, and the same technique can be chosen only once per turn. Move and Wait can be chosen twice.

Using a technique applies the cooldown shown in the table, whether or not it succeeds. For example, if a technique with a cooldown of 222 is used on turn ttt, it cannot be used on turns t+1t+1t+1 and t+2t+2t+2, and it can be used again from turn t+3t+3t+3.

  • A Move or Flash Step used as the first action must head from the current position to a cell inside the courtyard. A Move or Flash Step used as the second action may choose any direction, and if its destination is outside the courtyard when it is performed, the player stays in place.
  • If the destination of a Charge is outside the courtyard, the player does not move and attacks from the current position.

Simultaneous Resolution

The two players' actions are resolved in the following order.

Order Action Resolution rule
1 Flash Step icon Flash Step Resolve Flash Steps.
2 Guard icon Guard, Thrust icon Thrust Apply Guards and determine whether Thrusts hit. An opponent hit by a Thrust that is not blocked by Guard has their movement action canceled. A Guard stays in effect while that action is being resolved.
3 Move icon Move, Charge icon Charge Resolve Moves and the movement of Charges.
4 Sweep icon Sweep, Charge icon Charge, Shatter icon Shatter From the positions after movement, determine whether Sweeps, Charges, and Shatters hit.
5 Attack comparison If two attacks that are not blocked by Guard hit each other, compare their damage. If the damage differs, only the damage and push of the stronger attack are applied. If it is equal, neither side takes attack damage, and only the push of each attack is applied.
6 Push and health Resolve pushes and health loss. Pushes proceed simultaneously one cell at a time, and if both players would land on the same cell, the remaining pushes on both sides stop.

In each movement step, if both players' destinations are the same cell or they would swap positions, neither of them moves. A player also cannot move onto the cell of an opponent who is not moving in that step. A Charge whose movement is blocked attacks from the current position.

Thrust → vs Move ↑: Player 2's move is canceled and their health drops by 2.

Thrust Thrust icon vs Move Move icon: Player 2's move is canceled and their health drops by 2.

Charge → vs Thrust ←: Only the Charge's 3 damage and two-cell push are applied.

Charge Charge icon vs Thrust Thrust icon: Only the Charge's 3 damage and two-cell push are applied.

Sweep → vs Sweep ←: Both sides are pushed back one cell each without taking damage.

Sweep Sweep icon vs Sweep Sweep icon: Both sides are pushed back one cell each without taking damage.

Winning and Losing

The outcome is determined in the following order.

  1. After each action, a player whose health reaches 000 or who has been pushed out of the courtyard loses. If both players meet a losing condition in the same action, the game is a draw.
  2. After both actions, a player whose blessings reach 101010 wins.
  3. If no outcome is decided by turn 606060, the player with more blessings wins. If blessings are tied, the player with more health wins, and if both are tied, the game is a draw.

Example of pushing the opponent out of the courtyard with Charge.

Example of pushing the opponent out of the courtyard with Charge.

Design an AI that predicts your opponent's actions and becomes the final winner of the duel!

Input

At the start of the game, both players receive the following initial setup once.

INIT objective_r objective_c r1 c1 r2 c2

objective_r objective_c are the row and column of the spirit vein, and r1 c1 and r2 c2 are the starting row and column of Player 1 and Player 2, respectively. All coordinates are integers from 111 to 777.

The judge sends the following commands one line at a time.

Command Input Output
INIT Initial setup in the format above -
READY READY FIRST or READY SECOND OK
TURN Current state in the format below action1 action2
FINISH FINISH -

FIRST is Player 1 and SECOND is Player 2. Exit the program when you receive FINISH or when the input ends.

Turn Input

TURN time turn r1 c1 hp1 blessing1 r2 c2 hp2 blessing2 previous_action1 previous_action2
  • time: remaining total response time (milliseconds).
  • turn: the number of this turn (111 to 606060).
  • r1 c1 hp1 blessing1: Player 1's current row, column, health, and blessings.
  • r2 c2 hp2 blessing2: Player 2's current row, column, health, and blessings. The input always lists Player 1 first, then Player 2.
  • previous_action1 previous_action2: the two actions the opponent chose on the previous turn. On the first turn, this is 0 0, meaning Wait, Wait.

Track cooldowns using your own choices and the opponent's previous actions received in the input.

Action Output

Action Output format
Wait 0
Move 1 dir
Thrust 2 dir
Sweep 3 dir
Charge 4 dir
Guard 5 dir
Shatter 6 dir
Flash Step 7 dir

dir is one of U (up), R (right), D (down), and L (left). Flash Step can also use UR (up-right), DR (down-right), DL (down-left), and UL (up-left). Wait takes no direction.

Output both actions on one line, separated by a space. For example, 1 U 2 R means Move up and then Thrust right, and 7 UR 0 means Flash Step up-right and then Wait.

Limits

  • The total time spent on READY and all TURN responses is 1,000ms1{,}000\text{ms}1,000ms per player.
  • End each response with a newline and flush the buffer. Each response must be at most 128128128 bytes, including the newline.
  • Exceeding the time limit, an invalid output format, or an illegal action counts as a loss.

Example

In this example, the spirit vein is at (2,4)(2,4)(2,4), Player 1 starts at (4,3)(4,3)(4,3), and Player 2 starts at (4,5)(4,5)(4,5).

Both players receive the following initial input.

INIT 2 4 4 3 4 5

Player 1 receives READY FIRST and Player 2 receives READY SECOND, and each outputs OK.

The input and output for the first turn are as follows.

Player 1:

TURN 999 1 4 3 10 0 4 5 10 0 0 0
1 U 2 R

Player 2:

TURN 999 1 4 3 10 0 4 5 10 0 0 0
1 U 2 L

Both players move up and then thrust at each other. Since the damage is equal, both stay at 101010 health, and they end up at (3,3)(3,3)(3,3) and (3,5)(3,5)(3,5), respectively.

The input for the second turn includes the opponent's previous actions.

Player 1:

TURN 994 2 3 3 10 0 3 5 10 0 1 U 2 L
1 U 0

Player 2:

TURN 992 2 3 3 10 0 3 5 10 0 1 U 2 R
1 U 0

This turn, both players have a Thrust cooldown of 111. After both actions are resolved, they are at (2,3)(2,3)(2,3) and (2,5)(2,5)(2,5), respectively.

Sample code

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

Author

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

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