Logo
(追記) (追記ここまで)

8208번 - Difference 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB348947530.488%

문제

A word consisting of n lower-case letters of the English alphabet ('a'-'z') is given. We would like to choose a non-empty contiguous (i.e. one-piece) fragment of the word so as to maximise the difference in the number of occurrences of the most and the least frequent letter in the fragment. We are assuming that the least frequent letter has to occur at least once in the resulting fragment. In particular, should the fragment contain occurrences of only one letter, then the most and the least frequent letter in it coincide.

입력

The first line of the standard input holds one integer n (1 ≤ n ≤ 1,000,000) that denotes the length of the word. The second line holds a word consisting of n lower-case letters of the English alphabet.

출력

The first and only line of the standard output is to hold a single integer, equal to the maximum difference in the number of occurrences of the most and the least frequent letter that is attained in some non-empty contiguous fragment of the input word.

제한

예제 입력 1

10
aabbaaabab

예제 출력 1

3

힌트

The fragment that attains the difference of 3 in the number of occurrences of a and b is aaaba.

출처

Olympiad > Polish Olympiad in Informatics > POI 2010/2011 > Stage 2 2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /