CF844A.Diversity

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible.

String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.

计算字符串 s 中需要修改的最少字符数量,使得修改后的字符串中至少包含 k 个不同的字母;如果不可能实现,则输出相应提示。

字符串 s 仅由小写拉丁字母组成,且只允许将字符修改为小写拉丁字母。

输入格式

First line of input contains string s, consisting only of lowercase Latin letters (1 ≤ |s| ≤ 1000, |s| denotes the length of s).

Second line of input contains integer k (1 ≤ k ≤ 26).

输入的第一行包含字符串 ss,该字符串仅由小写拉丁字母组成(1 ≤ ∣s∣ ≤ 10001 ≤ |s| ≤ 1000,其中 ∣s∣|s| 表示 ss 的长度)。

输入的第二行包含整数 kk(1 ≤ k ≤ 261 ≤ k ≤ 26)。

输出格式

Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.

输出一行,包含所需的最少修改次数;如果无法实现,则输出单词 «impossible»(不带引号)。

输入输出样例

  • 输入#1

    yandex
    6

    输出#1

    0
  • 输入#2

    yahoo
    5

    输出#2

    1
  • 输入#3

    google
    7

    输出#3

    impossible

说明/提示

In the first test case string contains 6 different letters, so we don't need to change anything.

In the second test case string contains 4 different letters: {'a', 'h', 'o', 'y'}. To get 5 different letters it is necessary to change one occurrence of 'o' to some letter, which doesn't occur in the string, for example, {'b'}.

In the third test case, it is impossible to make 7 different letters because the length of the string is 6.

在第一个测试用例中,字符串包含 6 个不同的字母,因此无需进行任何修改。

在第二个测试用例中,字符串包含 4 个不同的字母:{'a', 'h', 'o', 'y'}。为了得到 5 个不同的字母,需要将其中一个 'o' 替换为字符串中未出现过的某个字母,例如 {'b'}。

在第三个测试用例中,由于字符串长度为 6,因此不可能得到 7 个不同的字母。

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

首页