Logo
(追記) (追記ここまで)

19188번 - Game 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
8 초 512 MB192228.571%

문제

Let us consider the following two-player game. Initially, there is some sequence of numbers. Then players in turns remove either the first or the last element of the sequence. If after some move, the sequence becomes one of several terminal sequences, then the game ends and the player who made the last move wins. If no player can make a move (because the sequence has length 0ドル$), then no player wins. Determine which player has a winning strategy in this game.

입력

The first line of input contains the number of test cases $z$. The descriptions of the test cases follow.

The first line of each test case contains an integer $n$ (1ドル \le n \le 10^6$) followed by $n$ integers $a_1, a_2, \ldots, a_n$ (0ドル \le a_i \le 10^9$), the initial sequence itself. The second line contains one integer $k,ドル the number of terminal sequences. The next $k$ lines contain descriptions of terminal sequences. Each of these lines contains an integer $m$ ($m \ge 1$), the length of the sequence, followed by $m$ elements of the sequence: $w_1, w_2, \ldots, w_m$ (0ドル \le w_i \le 10^9$). The total length of terminal sequences does not exceed 3ドル \cdot 10^6$.

Consecutive test cases will be separated by a single blank line.

출력

For each test case, print "FIRST" if the player who makes the first move wins, "SECOND" if the other player wins, or "DRAW" if no player wins.

제한

예제 입력 1

1
5 1 1 2 2 1
4
1 2
3 1 2 2
2 2 1
2 1 1

예제 출력 1

SECOND

힌트

출처

Camp > Petrozavodsk Programming Camp > Winter 2015 > Day 6: Jagiellonian U Contest J번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /