CF721B.Passwords

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.

Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice.

Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password k times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that.

Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds).

万尼亚成功登录了他最喜爱的网站 Codehorses。万尼亚总共使用了 nn 个互不相同的密码,但他记不清注册 Codehorses 时具体使用的是哪一个。

万尼亚将按密码长度非递减的顺序输入密码;对于长度相同的密码,他将以任意顺序输入。一旦万尼亚输入了正确的密码,他将立即登录网站。万尼亚不会重复输入任何一个密码。

万尼亚输入任一密码均需耗时 1 秒。但若万尼亚已连续输入了 kk 次错误密码,则他必须等待 5 秒后才能进行下一次尝试。万尼亚每次尝试都尽可能快地进行,即:在每一个他能够输入密码的时刻,他都会立刻执行该操作。

请确定:对万尼亚而言,在最优情况(所需总时间最少)和最坏情况(所需总时间最多)下,他分别需要多少秒才能登录 Codehorses。

输入格式

The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.

The next n lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters.

The last line of the input contains the Vanya's Codehorses password. It is guaranteed that the Vanya's Codehorses password is equal to some of his n passwords.

输入的第一行包含两个整数 nn 和 kk(1 ≤ n, k ≤ 1001 ≤ n, k ≤ 100)—— 分别表示 Vanya 的密码数量,以及尝试失败 kk 次后网站将封锁访问 5 秒。

接下来的 nn 行每行包含一个密码——这些密码两两不同、非空,且仅由拉丁字母和数字组成。每个密码的长度不超过 100 个字符。

输入的最后一行包含 Vanya 在 Codehorses 上的密码。保证该密码与他的 nn 个密码中的某一个完全相同。

输出格式

Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively.

输出两个整数——分别是 Vanya 在最佳情况和最差情况下完成 Codehorses 授权所需的时间(单位:秒)。

输入输出样例

  • 输入#1

    5 2
    cba
    abc
    bb1
    abC
    ABC
    abc

    输出#1

    1 15
  • 输入#2

    4 100
    11
    22
    1
    2
    22

    输出#2

    3 4

说明/提示

Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he enters another 4 passwords before. He spends 2 seconds to enter first 2 passwords, then he waits 5 seconds as soon as he made 2 wrong tries. Then he spends 2 more seconds to enter 2 wrong passwords, again waits 5 seconds and, finally, enters the correct password spending 1 more second. In summary in the worst case he is able to be authorized in 15 seconds.

Consider the second sample case. There is no way of entering passwords and get the access to the site blocked. As soon as the required password has length of 2, Vanya enters all passwords of length 1 anyway, spending 2 seconds for that. Then, in the best case, he immediately enters the correct password and the answer for the best case is 3, but in the worst case he enters wrong password of length 2 and only then the right one, spending 4 seconds at all.

考虑第一个样例。由于所有密码长度相同,万尼亚既可能在第一次尝试时就输入正确密码,也可能在最后一次尝试时才输入正确密码。如果他在第一次尝试时就输入了正确密码,则恰好花费 1 秒。因此,在最优情况下答案为 1。而另一方面,如果他在最后一次尝试时才输入正确密码,则在此之前他需先输入其余 4 个错误密码。他输入前 2 个错误密码共花费 2 秒;此时已累计 2 次错误尝试,需等待 5 秒;接着再输入接下来的 2 个错误密码,又花费 2 秒;再次因累计达到 2 次错误尝试而需等待 5 秒;最后输入正确密码,再花费 1 秒。综上,在最坏情况下,他可在 15 秒内完成认证。

考虑第二个样例。不存在导致网站访问被封锁的密码输入方式。由于目标密码长度为 2,万尼亚无论如何都会先输入所有长度为 1 的密码,为此花费 2 秒。随后,在最优情况下,他立即输入正确密码,故最优情况的答案为 3;而在最坏情况下,他先输入一个错误的长度为 2 的密码,再输入正确密码,总共花费 4 秒。

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

首页