CF202A.LLPS

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.

You are given string s consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.

We'll call a non-empty string s[_p_1_p_2... p__k] = _s__p_1_s__p_2... s__p__k (1  ≤  _p_1 < _p_2 < ... < p__k  ≤  |s|) a subsequence of string s = _s_1_s_2... s|s|, where |s| is the length of string s. For example, strings "abcb", "b" and "abacaba" are subsequences of string "abacaba".

String x = _x_1_x_2... x|x| is lexicographically larger than string y = _y_1_y_2... y|y| if either |x| > |y| and _x_1 = _y_1, _x_2 = _y_2, ..., x|y| = y|y|, or there exists such number r (r < |x|, r < |y|) that _x_1 = _y_1, _x_2 = _y_2, ..., x__r = y__r and x__r  +  1 > y__r  +  1. Characters in the strings are compared according to their ASCII codes. For example, string "ranger" is lexicographically larger than string "racecar" and string "poster" is lexicographically larger than string "post".

String s = _s_1_s_2... s|s| is a palindrome if it matches string rev(s) = s|s|s|s| - 1... _s_1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are "racecar", "refer" and "z".

本题的实际名称“字典序最大的回文子序列”过长,无法放入页面标题栏。

给定一个仅由小写英文字母组成的字符串 ss。请找出其字典序最大的回文子序列。

我们称一个非空字符串 s[p1p2…pk]=sp1sp2…spks[p_1p_2\ldots p_k] = s_{p_1}s_{p_2}\ldots s_{p_k}(其中 1≤p1<p2<…<pk≤∣s∣1 \leq p_1 < p_2 < \ldots < p_k \leq |s|)为字符串 s=s1s2…s∣s∣s = s_1s_2\ldots s_{|s|} 的一个子序列,这里 ∣s∣|s| 表示字符串 ss 的长度。例如,字符串 "abcb"、"b" 和 "abacaba" 都是字符串 "abacaba" 的子序列。

字符串 x=x1x2…x∣x∣x = x_1x_2\ldots x_{|x|} 在字典序上大于字符串 y=y1y2…y∣y∣y = y_1y_2\ldots y_{|y|},当且仅当满足以下任一条件:

  • ∣x∣>∣y∣|x| > |y|,且 x1=y1, x2=y2, …, x∣y∣=y∣y∣x_1 = y_1,\, x_2 = y_2,\, \ldots,\, x_{|y|} = y_{|y|};
  • 或存在某个整数 rr(满足 r<∣x∣r < |x| 且 r<∣y∣r < |y|),使得 x1=y1, x2=y2, …, xr=yrx_1 = y_1,\, x_2 = y_2,\, \ldots,\, x_r = y_r,且 xr+1>yr+1x_{r+1} > y_{r+1}。
    字符串中字符的比较依据其 ASCII 码值。例如,字符串 "ranger" 在字典序上大于 "racecar",字符串 "poster" 在字典序上大于 "post"。

字符串 s=s1s2…s∣s∣s = s_1s_2\ldots s_{|s|} 是一个回文串,当且仅当它与它的逆序字符串 rev(s)=s∣s∣s∣s∣−1…s1\mathrm{rev}(s) = s_{|s|}s_{|s|-1}\ldots s_1 完全相同。换言之,若一个字符串从左到右读与从右到左读完全一致,则该字符串为回文串。例如,回文串有 "racecar"、"refer" 和 "z"。

输入格式

The only input line contains a non-empty string s consisting of lowercase English letters only. Its length does not exceed 10.

唯一的一行输入包含一个非空字符串 ss,该字符串仅由小写英文字母组成。其长度不超过 1010。

输出格式

Print the lexicographically largest palindromic subsequence of string s.

输出字符串 ss 的字典序最大的回文子序列。

输入输出样例

  • 输入#1

    radar

    输出#1

    rr
  • 输入#2

    bowwowwow

    输出#2

    wwwww
  • 输入#3

    codeforces

    输出#3

    s
  • 输入#4

    mississipp

    输出#4

    ssss

说明/提示

Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr".

在字符串 “radar” 的所有不同子序列中,以下子序列是回文:"a"、"d"、"r"、"aa"、"rr"、"ada"、"rar"、"rdr"、"raar" 和 "radar"。其中字典序最大的是 "rr"。

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

首页