Game with coins

시간 제한12초메모리 제한1024 MB

요약
던진 동전과 주사위가 무작위 결과를 내는 미로 게임에서 매 턴 두 도구를 골라 말을 도착칸에 보내면 됩니다.
난이도

어려움10점 중 8점

유형
확률, 그래프, 게임 이론, BFS
정답자
아직 제출이 없습니다

문제

This problem is interactive.

Taja can easily win this game, but all of her friends couldn't. Now she offers you to play this game.

Game equipment consists of field n×nn \times n (5≤n≤405 \leq n \leq 40), the piece, two coins (COIN1, COIN2), two dices with cardinal directions (DICE1, DICE2), and a lot of one cell size blocks.

NameNumber of facesFaces
COIN1. Move coin2SLIDE, RAM
COIN2. Modification coin2PLACE, REMOVE
DICE1. First dice with directions4N (North), S (South), W (West), E (East)
DICE2. Second dice with directions8N (North), S (South), W (West), E (East), NW (Northwest), NE (Northeast), SW (Southwest), SE (Southeast)

Before the beginning of the game the piece and some blocks are placed on the field. Then the player makes moves such kind. At first, the player chooses a coin and tosses it for determine an action. Then he chooses one of the dices and rolls it for determine direction dirdir. After that one of the four action happens:

Coin stringAction
SLIDEMove the piece along empty cells in the direction of dirdir, until the piece collides a block or maze border
RAMMove the piece along empty cells in the direction of dirdir, until it collides a first block. Then move the piece and the block in the same direction, until moving block collides another block or field border
PLACEIf adjacent cell in the direction dirdir next to the piece is empty and is in the field, place a block on this cell
REMOVEIf adjacent cell in the direction dirdir next to the piece contains a block and is in the field, remove the block from this cell

The goal is to put the piece on the finish cell.

One query for this problem is one coin toss and one dice roll.

입력

First line of the standard input contains one integer number nn --- the size of the maze. Next nn lines contains nn characters "." (ASCII 4646) or <<\#>> (ASCII 3535), denoting empty cell and cell with block respectively.

Next line contains two integer numbers r_fr\_f and c_fc\_f --- row number and column number of the finish cell. The upper-left corner is (1,1)(1, 1), the bottom-right is (n,n)(n, n). Finish cell and initial cell are empty.

Next groups describes each move:

  • The first line of an group contains two integer numbers rr, cc --- row number and column number of the piece, or (−1,−1)(-1, -1), if the peace reaches the finish cell.
  • Next line contains action name shown on the coin.
  • Next line contains direction name shown on the dice.
  • If the current action is "RAM", next two strings contains two integer numbers r_1r\_1, c_1c\_1 and r_2r\_2, c_2c\_2, denotes then the piece collides a block with coordinates (r_1,c_1)(r\_1, c\_1) and moves that block to the cell (r_2,c_2)(r\_2, c\_2).

The north direction corresponds to decreasing row number. The south to increasing row number. The west direction to decreasing column number. The east direction to increasing column number.

Each side of any coin or dice is shown with the same probability.

출력

The standard output should consist of pair of lines: coin name and dice name. Coin name is the string "COIN1" or "COIN2". Dice name is the string "DICE1" or "DICE2".

힌트

The initial state of the maze for the sample is

And the representation of the path is shown below:

COIN2 →\rightarrow PLACE``DICE1 →\rightarrow WCOIN1 →\rightarrow RAM``DICE1 →\rightarrow S
COIN1 →\rightarrow RAM``DICE1 →\rightarrow WCOIN2 →\rightarrow PLACE``DICE2 →\rightarrow NE
COIN1 →\rightarrow RAM``DICE2 →\rightarrow NECOIN2 →\rightarrow REMOVE``DICE2 →\rightarrow NE
COIN2 →\rightarrow PLACE``DICE1 →\rightarrow SCOIN1 →\rightarrow SLIDE``DICE1 →\rightarrow W
COIN1 →\rightarrow RAM``DICE1 →\rightarrow SCOIN1 →\rightarrow SLIDE``DICE1 →\rightarrow E

예제1

  1. 예제 1

    입력
    5
    #....
    .....
    .....
    .....
    ..#..
    4 3
    1 5
    PLACE
    W
    1 5
    RAM
    S
    6 5
    6 5
    5 5
    RAM
    W
    5 3
    5 1
    5 2
    PLACE
    NE
    5 2
    RAM
    NE
    4 3
    2 5
    3 4
    REMOVE
    NE
    3 4
    PLACE
    S
    3 4
    SLIDE
    W
    3 1
    RAM
    S
    5 1
    5 1
    4 1
    SLIDE
    E
    -1 -1
    
    예상 출력
    
    
    
    
    
    
    
    COIN2
    DICE1
    
    COIN1
    DICE1
    
    
    
    COIN1
    DICE1
    
    
    
    COIN2
    DICE2
    
    COIN1
    DICE2
    
    
    
    COIN2
    DICE2
    
    COIN2
    DICE1
    
    COIN1
    DICE1
    
    COIN1
    DICE1
    
    
    
    COIN1
    DICE1