아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Gravity Grid

면접 대비

시간 제한1초메모리 제한512 MB

요약
주어진 순서대로 타일을 떨어뜨리며 사목 게임을 진행하고, 가로, 세로, 대각선으로 k개를 먼저 연결한 사람과 그 수를 출력하거나 무승부를 출력한다.
난이도

보통10점 중 5점

유형
시뮬레이션, 구현, 배열, 행렬
정답자
아직 제출이 없습니다

문제

Alice and Bob are playing a generalized version of Connect Four. In their game, the board consists of ww columns of height hh and the goal is to be the first player to complete a row of kk tiles of equal colour, either vertically, horizontally or diagonally. The two players alternate dropping their tiles into one of the columns, with Alice using red tiles and going first and Bob using yellow tiles and going second. Once a tile is dropped, it falls down to the bottommost available position, making that position no longer available. Once a column has hh tiles in it, it becomes full and the players can no longer drop their tiles there.

Figure G.1: Visualisation of the sample cases, showing the state of the game after 0, 3, 8 and 12 moves, respectively. Alice's tiles are shown in red, Bob's tiles in yellow.

As Alice and Bob found it quite challenging to keep track of the winning condition, they just kept playing until the board was completely filled with tiles. They recorded a log of the moves they made and asked you to tell them who won the game, and on what turn they did so. If neither player managed to complete a row, the game ends in a draw, so report that instead.

입력

The input consists of:

  • One line with three integers hh, ww and kk (h,w≥1,h⋅w≤250,000,1≤k≤max⁡(h,w)h, w \ge 1, h \cdot w \le 250\\,000, 1 \le k \le \max(h,w)). The columns are numbered from 11 to ww.
  • One line with h⋅wh\cdot w integers a_1,…,a_h⋅wa\_1,\dots,a\_{h\cdot w} (1≤a_i≤w1 \le a\_i \le w for each ii), where a_ia\_i is the index of the column that the iith tile was dropped in. Odd indices correspond to Alice's moves and even indices correspond to Bob's moves. Each column appears exactly hh times in this list.

출력

Output the winner of the game (A for Alice or B for Bob), followed by the number of moves needed to decide the winner. If the game ends in a draw, output D instead.

예제3

  1. 예제 1

    입력
    4 3 2
    1 1 2 3 3 2 2 1 1 2 3 3
    
    예상 출력
    A 3
    
  2. 예제 2

    입력
    4 3 3
    1 1 2 3 3 2 2 1 1 2 3 3
    
    예상 출력
    B 8
    
  3. 예제 3

    입력
    4 3 4
    1 1 2 3 3 2 2 1 1 2 3 3
    
    예상 출력
    D