CF1092C.Prefixes and Suffixes

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Ivan wants to play a game with you. He picked some string ss of length nn consisting only of lowercase Latin letters.

You don't know this string. Ivan has informed you about all its improper prefixes and suffixes (i.e. prefixes and suffixes of lengths from 11 to n−1n-1), but he didn't tell you which strings are prefixes and which are suffixes.

Ivan wants you to guess which of the given 2n−22n-2 strings are prefixes of the given string and which are suffixes. It may be impossible to guess the string Ivan picked (since multiple strings may give the same set of suffixes and prefixes), but Ivan will accept your answer if there is at least one string that is consistent with it. Let the game begin!

伊万想和你玩一个游戏。他选择了一个长度为 nn 的字符串 ss,该字符串仅由小写拉丁字母组成。

你并不知道这个字符串。伊万已将该字符串的所有非平凡前缀和后缀(即长度为 11 到 n−1n-1 的所有前缀和后缀)告诉了你,但他并未说明哪些字符串是前缀、哪些是后缀。

伊万希望你判断:在给定的 2n−22n-2 个字符串中,哪些是该字符串的前缀,哪些是其后缀。可能无法唯一确定伊万所选的字符串(因为多个不同字符串可能产生完全相同的前缀与后缀集合),但只要你的答案与至少一个字符串相容,伊万就会接受。游戏开始!

输入格式

The first line of the input contains one integer number nn (2≤n≤1002 \le n \le 100) — the length of the guessed string ss.

The next 2n−22n-2 lines are contain prefixes and suffixes, one per line. Each of them is the string of length from 11 to n−1n-1 consisting only of lowercase Latin letters. They can be given in arbitrary order.

It is guaranteed that there are exactly 22 strings of each length from 11 to n−1n-1. It is also guaranteed that these strings are prefixes and suffixes of some existing string of length nn.

输入的第一行包含一个整数 nn(2≤n≤1002 \le n \le 100),表示被猜测的字符串 ss 的长度。

接下来的 2n−22n-2 行包含所有前缀和后缀,每行一个。每个字符串的长度为 11 到 n−1n-1,且仅由小写拉丁字母组成。这些字符串以任意顺序给出。

保证对于每个长度 11 到 n−1n-1,恰好有 22 个字符串。同时保证这些字符串是某个长度为 nn 的真实字符串的前缀和后缀。

输出格式

Print one string of length 2n−22n-2 — the string consisting only of characters 'P' and 'S'. The number of characters 'P' should be equal to the number of characters 'S'. The ii-th character of this string should be 'P' if the ii-th of the input strings is the prefix and 'S' otherwise.

If there are several possible answers, you can print any.

输出一个长度为 2n−22n-2 的字符串——该字符串仅由字符 'P' 和 'S' 组成,且 'P' 的个数等于 'S' 的个数。该字符串的第 ii 个字符应为 'P',当且仅当输入的第 ii 个字符串是某个字符串的前缀(prefix);否则为 'S'。

若存在多个可能的答案,输出任意一个即可。

输入输出样例

  • 输入#1

    5
    ba
    a
    abab
    a
    aba
    baba
    ab
    aba

    输出#1

    SPPSPSPS
  • 输入#2

    3
    a
    aa
    aa
    a

    输出#2

    PPSS
  • 输入#3

    2
    a
    c

    输出#3

    PS

说明/提示

The only string which Ivan can guess in the first example is "ababa".

The only string which Ivan can guess in the second example is "aaa". Answers "SPSP", "SSPP" and "PSPS" are also acceptable.

In the third example Ivan can guess the string "ac" or the string "ca". The answer "SP" is also acceptable.

第一个样例中,Ivan 唯一能猜出的字符串是 "ababa"。

第二个样例中,Ivan 唯一能猜出的字符串是 "aaa"。答案 "SPSP"、"SSPP" 和 "PSPS" 也同样可接受。

第三个样例中,Ivan 可以猜出字符串 "ac" 或字符串 "ca"。答案 "SP" 同样可接受。

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

首页