A14341 | Palindrome Game (hard version)
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The first line contains a single integer $t$ ( $1 \le t \le 10^3$ ). Then $t$ test cases follow.
The first line of each test case contains a single integer $n$ ( $1 \le n \le 10^3$ ).
The second line of each test case contains the string $s$ of length $n$ , consisting of the characters '0' and '1'. It is guaranteed that the string $s$ contains at least one '0'.
Note that there is no limit on the sum of $n$ over test cases.
The first line of each test case contains a single integer $n$ ( $1 \le n \le 10^3$ ).
The second line of each test case contains the string $s$ of length $n$ , consisting of the characters '0' and '1'. It is guaranteed that the string $s$ contains at least one '0'.
Note that there is no limit on the sum of $n$ over test cases.
输入格式
For each test case print a single word in a new line:
- "ALICE", if Alice will win the game,
- "BOB", if Bob will win the game,
- "DRAW", if the game ends in a draw.
- "ALICE", if Alice will win the game,
- "BOB", if Bob will win the game,
- "DRAW", if the game ends in a draw.
输出格式
In the first test case of example,
- in the $1$ -st move, Alice will use the $2$ -nd operation to reverse the string, since doing the $1$ -st operation will result in her loss anyway. This also forces Bob to use the $1$ -st operation.
- in the $2$ -nd move, Bob has to perform the $1$ -st operation, since the $2$ -nd operation cannot be performed twice in a row. All characters of the string are '1', game over.
Alice spends $0$ dollars while Bob spends $1$ dollar. Hence, Alice wins.In the second test case of example,
- in the $1$ -st move Alice has to perform the $1$ -st operation, since the string is currently a palindrome.
- in the $2$ -nd move Bob reverses the string.
- in the $3$ -rd move Alice again has to perform the $1$ -st operation. All characters of the string are '1', game over.
Alice spends $2$ dollars while Bob spends $0$ dollars. Hence, Bob wins.
- in the $1$ -st move, Alice will use the $2$ -nd operation to reverse the string, since doing the $1$ -st operation will result in her loss anyway. This also forces Bob to use the $1$ -st operation.
- in the $2$ -nd move, Bob has to perform the $1$ -st operation, since the $2$ -nd operation cannot be performed twice in a row. All characters of the string are '1', game over.
Alice spends $0$ dollars while Bob spends $1$ dollar. Hence, Alice wins.In the second test case of example,
- in the $1$ -st move Alice has to perform the $1$ -st operation, since the string is currently a palindrome.
- in the $2$ -nd move Bob reverses the string.
- in the $3$ -rd move Alice again has to perform the $1$ -st operation. All characters of the string are '1', game over.
Alice spends $2$ dollars while Bob spends $0$ dollars. Hence, Bob wins.
输入输出样例
输入 #1
3 3 110 2 00 4 1010
输出 #1
ALICE BOB ALICE
In the first test case of example,
- in the $1$ -st move, Alice will use the $2$ -nd operation to reverse the string, since doing the $1$ -st operation will result in her loss anyway. This also forces Bob to use the $1$ -st operation.
- in the $2$ -nd move, Bob has to perform the $1$ -st operation, since the $2$ -nd operation cannot be performed twice in a row. All characters of the string are '1', game over.
Alice spends $0$ dollars while Bob spends $1$ dollar. Hence, Alice wins.In the second test case of example,
- in the $1$ -st move Alice has to perform the $1$ -st operation, since the string is currently a palindrome.
- in the $2$ -nd move Bob reverses the string.
- in the $3$ -rd move Alice again has to perform the $1$ -st operation. All characters of the string are '1', game over.
Alice spends $2$ dollars while Bob spends $0$ dollars. Hence, Bob wins.
- in the $1$ -st move, Alice will use the $2$ -nd operation to reverse the string, since doing the $1$ -st operation will result in her loss anyway. This also forces Bob to use the $1$ -st operation.
- in the $2$ -nd move, Bob has to perform the $1$ -st operation, since the $2$ -nd operation cannot be performed twice in a row. All characters of the string are '1', game over.
Alice spends $0$ dollars while Bob spends $1$ dollar. Hence, Alice wins.In the second test case of example,
- in the $1$ -st move Alice has to perform the $1$ -st operation, since the string is currently a palindrome.
- in the $2$ -nd move Bob reverses the string.
- in the $3$ -rd move Alice again has to perform the $1$ -st operation. All characters of the string are '1', game over.
Alice spends $2$ dollars while Bob spends $0$ dollars. Hence, Bob wins.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted