CF305E.Playing with String

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

两人进行如下字符串游戏。游戏开始时,双方拥有某个字符串 ss。双方轮流行动,无法行动者判负。

游戏开始前,字符串被写在一张纸上,每个字符占据一个格子。

初始状态示例:s=“abacaba”s = \text{``abacaba''}

一名玩家的一次行动由以下步骤构成:

  1. 玩家选择一张当前可用的、上面写有某个字符串的纸。记该字符串为 tt。注意:初始时仅有一张纸可用。
  2. 玩家在字符串 t=t1t2…t∣t∣t = t_1 t_2 \dots t_{|t|} 中选择一个位置 ii(1≤i≤∣t∣1 \le i \le |t|),使得存在某个正整数 ll(满足 0<i−l0 < i - l 且 i+l≤∣t∣i + l \le |t|),使得以下等式成立:
    ti−1=ti+1,  ti−2=ti+2,  …,  ti−l=ti+lt_{i-1} = t_{i+1},\; t_{i-2} = t_{i+2},\; \dots,\; t_{i-l} = t_{i+l}。
  3. 玩家将位置 ii 上的字符所在格子剪下。操作完成后,他得到三张新纸:第一张纸上写有字符串 t1t2…ti−1t_1 t_2 \dots t_{i-1},第二张纸上仅有一个字符 tit_i,第三张纸上写有字符串 ti+1ti+2…t∣t∣t_{i+1} t_{i+2} \dots t_{|t|}。

对字符串 s=“abacaba”s = \text{``abacaba''} 执行操作(取 i=4i = 4)的示例

你的任务是:假设双方均以最优策略进行游戏,判断获胜方。若先手玩家获胜,请找出其第一步中应剪下的字符位置(即最优的 ii 值);若存在多个最优位置,请输出其中最小的一个。

输入格式

The first line contains string s (1 ≤ |s| ≤ 5000). It is guaranteed that string s only contains lowercase English letters.

第一行包含字符串 ss(1 ≤ ∣s∣ ≤ 50001 \leq |s| \leq 5000)。保证字符串 ss 仅由小写英文字母组成。

输出格式

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|).

如果第二位玩家获胜,则在单独一行中输出 "Second"(不带引号)。否则,在第一行输出 "First"(不带引号),在第二行输出最小的可能致胜操作——整数 ii(1 ≤ i ≤ ∣s∣1 \le i \le |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.

在第一个样例中,先手玩家有多个获胜操作,但最小的操作是切割位置 2 处的字符。

在第二个样例中,先手玩家没有可用的操作。

输入解题思路,AI测评打分。不知道怎么写?

首页