A9025 | Playing with String
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Two people play the following string game. Initially the players have got some string $s$ . The players move in turns, the player who cannot make a move loses.
Before the game began, the string is written on a piece of paper, one letter per cell.
An example of the initial situation at $s$ = "abacaba"A player's move is the sequence of actions:
1. The player chooses one of the available pieces of paper with some string written on it. Let's denote it is $t$ . Note that initially, only one piece of paper is available.
2. The player chooses in the string $t=t_{1}t_{2}...\ t_{|t|}$ character in position $i$ $(1<=i<=|t|)$ such that for some positive integer $l$ $(0<i-l; i+l<=|t|)$ the following equations hold: $t_{i-1}=t_{i+1}$ , $t_{i-2}=t_{i+2}$ , ..., $t_{i-l}=t_{i+l}$ .
3. Player cuts the cell with the chosen character. As a result of the operation, he gets three new pieces of paper, the first one will contain string $t_{1}t_{2}...\ t_{i-1}$ , the second one will contain a string consisting of a single character $t_{i}$ , the third one contains string $t_{i+1}t_{i+2}...\ t_{|t|}$ .
An example of making action $(i=4)$ with string $s$ = «abacaba»Your task is to determine the winner provided that both players play optimally well. If the first player wins, find the position of character that is optimal to cut in his first move. If there are multiple positions, print the minimal possible one.
Before the game began, the string is written on a piece of paper, one letter per cell.
An example of the initial situation at $s$ = "abacaba"A player's move is the sequence of actions:
1. The player chooses one of the available pieces of paper with some string written on it. Let's denote it is $t$ . Note that initially, only one piece of paper is available.
2. The player chooses in the string $t=t_{1}t_{2}...\ t_{|t|}$ character in position $i$ $(1<=i<=|t|)$ such that for some positive integer $l$ $(0<i-l; i+l<=|t|)$ the following equations hold: $t_{i-1}=t_{i+1}$ , $t_{i-2}=t_{i+2}$ , ..., $t_{i-l}=t_{i+l}$ .
3. Player cuts the cell with the chosen character. As a result of the operation, he gets three new pieces of paper, the first one will contain string $t_{1}t_{2}...\ t_{i-1}$ , the second one will contain a string consisting of a single character $t_{i}$ , the third one contains string $t_{i+1}t_{i+2}...\ t_{|t|}$ .
An example of making action $(i=4)$ with string $s$ = «abacaba»Your task is to determine the winner provided that both players play optimally well. If the first player wins, find the position of character that is optimal to cut in his first move. If there are multiple positions, print the minimal possible one.
输入格式
The first line contains string $s$ ( $1<=|s|<=5000$ ). It is guaranteed that string $s$ only contains lowercase English letters.
输出格式
If the second player wins, print in the single line "Second" (without the quotes). Otherwise, print in the first line "First" (without the quotes), and in the second line print the minimal possible winning move — integer $i$ $(1<=i<=|s|)$ .
输入输出样例
输入 #1
abacaba
输出 #1
First 2
输入 #2
abcde
输出 #2
Second
In the first sample the first player has multiple winning moves. But the minimum one is to cut the character in position $2$ .
In the second sample the first player has no available moves.
In the second sample the first player has no available moves.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted