time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

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).

Input

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.

Output

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.

Examples

input

5 2

cba

abc

bb1

abC

ABC

abc

output

1 15

input

4 100

11

22

1

2

22

output

3 4

Note

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.

【题解】



只要找到和正确的密码一样长的“试验”密码即可。

所以密码本身是什么根本不重要。只要记录密码的长度就好。

具体的,记录密码长度为i的密码个数为num[i];

求前缀和。

然后设正确密码的长度为key;

和key一样长的密码组成的序列。

把正确密码放在最前面是最优的,把正确密码放在最后面则是最坏情况。

处理一下输出的情况即可。

看代码吧。

#include <cstdio>
#include <cstring> const int MAXN = 150; int num[MAXN] = { 0 }, n, k, sum[MAXN] = { 0 },key,p = 0;
char s[MAXN]; int main()
{
//freopen("F:\\rush.txt", "r", stdin);
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++)
{
scanf("%s", s);
int len = strlen(s);
num[len]++;
}
scanf("%s", s);
key = strlen(s);
for (int i = 1; i <= key; i++)
sum[i] = sum[i - 1] + num[i];
p = sum[key - 1];
for (int i = 1;i <= sum[key-1];i++)
if ((i%k) == 0)//要多加的时间
p += 5;
if (num[key] == 1)//如果和正确密码一样长的只有正确密码本身
printf("%d %d\n", p + 1, p + 1);
else
{
printf("%d ", p + 1);//最优情况
for (int i = sum[key - 1] + 1; i <= sum[key] - 1; i++) //最坏情况是在最后面
{
p++;
if ((i%k) == 0)
p += 5;
}
printf("%d\n", p + 1);
}
return 0;
}

【37.21%】【codeforces 721B】Passwords的更多相关文章

  1. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  2. codeforces 721B B. Passwords(贪心)

    题目链接: B. Passwords time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. 【21.37%】【codeforces 579D】"Or" Game

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【35.37%】【codeforces 556C】Case of Matryoshkas

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【81.37%】【codeforces 734B】Anton and Digits

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【21.21%】【codeforces round 382D】Taxes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【21.58%】【codeforces 746D】Green and Black Tea

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. 【codeforces 757D】Felicity's Big Secret Revealed

    [题目链接]:http://codeforces.com/problemset/problem/757/D [题意] 给你一个01串; 让你分割这个01串; 要求2切..n+1切; 对于每一种切法 所 ...

  9. 【codeforces 757E】Bash Plays with Functions

    [题目链接]:http://codeforces.com/problemset/problem/757/E [题意] 给你q个询问; 每个询问包含r和n; 让你输出f[r][n]; 这里f[0][n] ...

随机推荐

  1. mk-编译信息的意义

    今天第一次看Android.mk文件,内容如下 # Copyright 2007-2008 The Android Open Source Project 2 3 LOCAL_PATH:= $(cal ...

  2. 可变参数的实现my_sprintf

    #include "stdafx.h" #include <stdio.h> #include <stdarg.h> void my_sprintf(cha ...

  3. make 2>&1 | tee build.log

    make 2>&1 | tee build.log 保存编译log,方便问题查找

  4. cwRsync 同步时报错 STATUS_ACCESS_VIOLATION

    cwRsync 同步时报错 STATUS_ACCESS_VIOLATION windows XP  执行  cwRsync  同步时报错: 2 [main] rsync 3044 _cygtls::h ...

  5. HTML的SEO(搜索引擎优化)标准

    HTML的SEO(搜索引擎优化)标准 一.总结 这个做seo的时候要多看,做网站优化的时候 1. SEO(搜索引擎优化):通过总结搜索引擎的排名规律,对网站进行合理优化,使你的网站在百度和Google ...

  6. vue-cli打包项目后,可以修改配置文件

    问题: 前端需要修改后台服务器地址url,写好的配置文件会在npm run build 后压缩在一起,传到运行的前端服务器上后,需要到前端打包的源码,找到url地址进行修改.如果不在打包的源码修改,则 ...

  7. python基础--数值类型和序列类型

    Python中数值类型:int(整数),float(浮点数),True/False(布尔值,首字母必须大写) int:1    #任意整数 float:2.3   #小数 python赋值: a = ...

  8. 程序中图片透明 函数(使用SetBkColor API函数)

    void DrawTransparentBitmap(HDC  hdc,  HBITMAP  hBitmap,  short  xStart,  short  yStart,  COLORREF  c ...

  9. 安装filezilla client报错libgnutls版本旧

    http://blog.csdn.net/mofabang/article/details/9212217

  10. 第三方插件将数据转成json

    1.需要使用第三方jar commons-beanutils-1.7.0.jar /commons-collections-3.1.jar/commons-lang-2.5jar /commons-l ...