CF354B Game with Strings
题目描述
## 题意翻译
给定一个 $n\times n$ 的表格,表格的每个位置都填写有一个小写字母,从上到下,行号依次为 $1$ 至 $n$ ,从左到右,列号依次为 $1$ 到 $n$,第 $i$ 行第 $j$ 列的字母我们用 $T_{i,j}$ 表示。
我们定义长度为 $1$ 的“好” 字符串 $s$ 为 $T_{1,1}$,我们假设长度为 $k$ 的“好”字符串为 $T_{r_1,c_1}+T_{r_2,c_2}+...+T_{r_k,c_k}$,则 $T_{r_1,c_1}+T_{r_2,c_2}...T_{r_k,c_k}+T_{r_k+1,c_k}$ 或者 $T_{r_1,c_1}+T_{r_2,c_2}...T_{r_k,c_k}+T_{r_k,c_k+1}$ 也是“好”字符串。
现有一空串,有两人轮流挑选字母,从末尾加入该串,并且必须保证该串在任意时刻都是“好”字符串,经过 $2n-1$ 次操作后
- 如果该串中 $a$ 的个数比 $b$ 多,则第一个人获胜;
- 如果该串中 $a$ 的个数比 $b$ 少,则第二个人获胜;
- 如果该串中 $a$ 的个数与 $b$ 的个数相等,则平局。
请输出最终结果。
输入格式
第一行为一个整数 $1\le n\le 20$。
接下来 $n$ 行每行为一个长度为 $n$ 的只包含小写字母的字符串。
输出格式
如果第一个人获胜,输出 "FIRST";如果第二个人获胜,输出 "SECOND";如果平局,输出 "DRAW"。
说明/提示
Consider the first sample:
Good strings are strings: a, ab, ac, abd, acd.
The first player moves first and adds letter a to the string, as there is only one good string of length $ 1 $ . Then the second player can add b or c and the game will end with strings abd or acd, correspondingly. In the first case it will be a draw (the string has one a and one b), in the second case the first player wins. Naturally, in this case the second player prefers to choose letter b and end the game with a draw.
Consider the second sample:
Good strings are: x, xa, xay.
We can see that the game will end with string xay and the first player wins.