codeforces 721 Passwords
来源:互联网 发布:php连接数据库语句 编辑:程序博客网 时间:2024/05/20 06:30
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).
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.
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.
5 2cbaabcbb1abCABCabc
1 15
4 10011221222
3 4
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int main(){int n,k;char mima[110];int a[110];while(~scanf("%d%d",&n,&k)){for(int i = 0; i <= n; i++){memset(mima,'\0',sizeof(mima));scanf("%s",mima);a[i] = strlen(mima);}sort(a,a+n);int t = lower_bound(a,a+n,a[n]) - a;int e = upper_bound(a,a+n,a[n]) - a;int min_T = 0,max_T = 0;min_T = t / k * 5 + (t + 1);max_T = (e - 1) / k * 5 + e;printf("%d %d\n",min_T,max_T);}return 0;}
- CodeForces 721B Passwords
- codeforces 721 Passwords
- 【37.21%】【codeforces 721B】Passwords
- codeforces 721B B. Passwords -- by lethalboyd
- CodeForces 721B. Passwords(水题,贪心)
- Passwords Codeforces Round#374-B
- Passwords
- CodeForces Gym 100989E Accepted Passwords
- Codeforces #374(Div.2)B. Passwords【模拟】
- Codeforces Round #374 (Div. 2) B. Passwords 贪心
- Codeforces Gym 101174 E. Passwords (AC 自动机 + DP)
- Codeforces Round #374 (Div. 2) B. Passwords —— 基础题
- B. Passwords
- Chrome passwords
- 【codeforces 721B】B. Passwords【输入密码按长度非递减顺序输入,每输一次耗时1秒,输错k次等待5秒,最后一行为正确密码,问消耗的最少和最多时间】
- get Firefox Passwords
- Encoding Passwords with Acegi
- zoj 2514 Generate Passwords
- AngularJS: $timeout $interval
- Linux系统GNU make
- activity->fragment
- Android之Notification
- Java中实现多线程的两种方式之间的区别
- codeforces 721 Passwords
- 解决sublime在编译出错或警告时额外显示系统path的问题
- DFT,FFT和卷积(笔记)
- lucene入门及安装配置
- 心路杂谈
- Android不同分辨率图片实际显示大小的计算
- iOS开发常用技巧-常见问题篇
- 【Java】Object类的方法
- nameidata路径查找辅助结构