Average Substring Value

시간 제한1초메모리 제한2048 MB

요약
숫자로 이루어진 문자열이 주어질 때, 모든 부분 문자열의 최댓값 평균을 정확한 분수로 출력한다.
난이도

보통10점 중 6점

유형
수학, 조합론, 구현
정답자
아직 제출이 없습니다

문제

Let ss be a nonempty string consisting entirely of base-1010 digits (0-9). If the length of ss is n,n, number the digits 1,2,3,…,n1, 2, 3, \ldots, n from left to right, and for 1≤i≤j≤n,1 \leq i \leq j \leq n, let s\[i,j]s\[i,j] denote the substring consisting of the digits from position ii to position jj, inclusive. (It follows that we are only considering nonempty substrings.) Assign a value to each substring that is simply equal to the largest digit in the substring. What is the average value of the substrings of ss?

Note that two different substrings may be identical (as strings), but for the purposes of this problem they are treated as distinct. For example, if s=s = 1010, then s\[1,2]=s\[3,4]=s\[1,2] = s\[3,4] = 10 are distinct substrings (both with value 11).

입력

The input is a single nonempty string, s,s, of base-1010 digits. The length of ss is at most 200,000200\\,000.

출력

Output a line containing the average value of the substrings of ss. If the average is an integer, print the integer. If the average is a proper fraction, i.e., is equal to a/ba/b, where aa and bb are positive integers and a<ba < b, print this fraction in lowest terms, with a '/' symbol separating the numerator and denominator. If the average is greater than 11 and does not simplify to an integer, print the whole part followed by the proper fractional part, separated by a space, with the proper fractional part in lowest terms and formatted as described in the previous sentence.

예제4

  1. 예제 1

    입력
    123
    
    예상 출력
    2 1/3
    
  2. 예제 2

    입력
    4084
    
    예상 출력
    6
    
  3. 예제 3

    입력
    1010
    
    예상 출력
    4/5
    
  4. 예제 4

    입력
    00000
    
    예상 출력
    0