CF864B.Polycarp and Letters

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.

Let A be a set of positions in the string. Let's call it pretty if following conditions are met:

  • letters on positions from A in the string are all distinct and lowercase;
  • there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and _a_1 < j < _a_2 for some _a_1 and _a_2 from A).

Write a program that will determine the maximum number of elements in a pretty set of positions.

波利卡普喜欢小写字母,讨厌大写字母。有一次,他得到了一个字符串 ss,该字符串仅由小写和大写的拉丁字母组成。

设 AA 是字符串中位置的一个集合。若满足以下条件,则称其为“优美集合”:

  • 字符串中位于集合 AA 中的位置上的字母全部互不相同且均为小写字母;
  • 字符串中不存在位于集合 AA 中任意两个位置之间的大写字母(即:不存在某个 jj,使得 s[j]s[j] 是大写字母,且对 AA 中的某两个元素 a1a_1 和 a2a_2 满足 a1<j<a2a_1 < j < a_2)。

请编写一个程序,求出优美集合中位置数量的最大值。

输入格式

The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.

The second line contains a string s consisting of lowercase and uppercase Latin letters.

第一行包含一个整数 nn(1≤n≤2001 \leq n \leq 200)——字符串 ss 的长度。

第二行包含一个字符串 ss,由小写和大写拉丁字母组成。

输出格式

Print maximum number of elements in pretty set of positions for string s.

输出字符串 ss 的“优美”位置集合中元素的最大数量。

输入输出样例

  • 输入#1

    11
    aaaaBaabAbA

    输出#1

    2
  • 输入#2

    12
    zACaAbbaazzC

    输出#2

    3
  • 输入#3

    3
    ABC

    输出#3

    0

说明/提示

In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.

In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.

In the third example the given string s does not contain any lowercase letters, so the answer is 0.

在第一个例子中,所期望的位置可以是 6 和 8,也可以是 7 和 8。位置 6 和 7 处的字符为小写字母 'a',位置 8 处的字符为小写字母 'b'。位置对 1 和 8 不满足要求,因为这两个位置之间存在一个大写字母 'B'。

在第二个例子中,所期望的位置可以是 7、8 和 11。还存在其他方式选择由三个元素构成的“优美集合”。

在第三个例子中,给定字符串 s 不包含任何小写字母,因此答案为 0。

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

首页