아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Alphabet Contest

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

요약
최종 문자열을 A부터 Z까지 증가하는 부분수열 여러 개로 나누되, 건너뛴 글자 수의 합이 k 이하가 되도록 참가자 수를 최소로 구한다.
난이도

보통10점 중 7점

유형
동적 계획법, 그리디, 문자열, 이분 탐색
정답자
아직 제출이 없습니다

문제

Kindergarten graduates participate in English alphabet Olympiad. The main task is to pronounce English letters in the alphabet order without repeats.

Children can start to pronounce letters at any moment, even when the other participant has not finished yet. At the same time, the teacher writes all pronounced letters into one common string. The task is not easy for children and sometimes they make mistakes such as skipping letters. For each participant the number of mistakes they make is the number of skipped letters. The total number of mistakes for all children doesn’t exceed kk. If at some point participant is tired to pronounce letters, (s)he stops, and all the remaining letters are not counted as mistakes.

You know kk and the final string, your task is to find the minimum possible number of participants, or say that data is not correct.

입력

The first line contains a single integer kk (0≤k≤10000 \le k \le 1000) — the maximum number of skipped letters.

The second line contains teacher’s string ss — all pronounced letters. ss consists of capital English letters and the length of the string does not exceed 10001000.

출력

Print single word “Impossible” in a single line if the data is incorrect (it isn’t possible to get this line with missing only kk letters), otherwise print single integer — the minimum number of participants in the Olympiad.

힌트

In the first example, the rows separately for each participant might look like this:

  • Participant 1: ABD — 1 mistake;
  • Participant 2: BC — 1 mistake;
  • Participant 3: BD — 2 mistakes;
  • Participant 4: AB — 0 mistakes;

In the second example:

  • Participant 1: INO — 12 mistakes;
  • Participant 2: NOP — 13 mistakes;
  • Participant 3: LS — 17 mistakes;
  • Participant 4: I — 8 mistakes;

예제3

  1. 예제 1

    입력
    5
    ABDBCBADB
    
    예상 출력
    4
    
  2. 예제 2

    입력
    100
    INNOPOLIS
    
    예상 출력
    4
    
  3. 예제 3

    입력
    0
    ABB
    
    예상 출력
    Impossible