C. K-Dominant Character
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c.

You have to find minimum k such that there exists at least one k-dominant character.

Input

The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000).

Output

Print one number — the minimum value of k such that there exists at least one k-dominant character.

Examples
input

Copy
abacaba
output

Copy
2
input

Copy
zzzzz
output

Copy
1
input

Copy
abcde
output

Copy
3
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std; int main(){
string str;
while(cin>>str){
getchar();
// cout<<" len = "<<str.length()<<endl;
int ans = 1e6;
for(int i='a';i<='z';i++){
int k = , t = ;
for(int j=;j<str.length();j++){ if(str[j]==i)
t=;
else
t++;
k = max(k,t);
}
// cout<<" k = "<<k<<endl;
ans = min(k,ans);
}
cout<<ans<<endl;
}
}

[Codeforces-888C] - K-Dominant Character的更多相关文章

  1. Codeforces 888C: K-Dominant Character(水题)

    You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff ...

  2. K-Dominant Character CodeForces - 888C

    题目链接:https://vjudge.net/problem/CodeForces-888C 划一条线,使得不论怎么划线,都会出现一个特定的字符,那么这条线最短要多长. 用字符间隔考虑. 先判断哪些 ...

  3. Codeforces Round #754 (Div. 2) C. Dominant Character

    题目:Problem - C - Codeforces 如代码,一共有七种情况,注意不要漏掉  "accabba"  , "abbacca"  两种情况: 使用 ...

  4. Codeforces gym102152 K.Subarrays OR

    传送:http://codeforces.com/gym/102152/problem/K 题意:给定$n(n\le10^5)$个数$a_i(a_i\le10^9)$,对于任一个子数组中的数进行或操作 ...

  5. Codeforces 101572 D - Distinctive Character

    D - Distinctive Character 思路:bfs 使最大的匹配数最小,转换一下,就是使最小的不匹配数最大,用bfs找最大的距离 代码: #pragma GCC optimize(2) ...

  6. codeforces 1133E K Balanced Teams

    题目链接:http://codeforces.com/contest/1133/problem/E 题目大意: 在n个人中找到k个队伍.每个队伍必须满足最大值减最小值不超过5.求满足条件k个队伍人数的 ...

  7. Codeforces 1133E - K Balanced Teams - [DP]

    题目链接:https://codeforces.com/contest/1133/problem/C 题意: 给出 $n$ 个数,选取其中若干个数分别组成 $k$ 组,要求每组内最大值与最小值的差值不 ...

  8. codeforces 1269E K Integers (二分+树状数组)

    链接:https://codeforces.com/contest/1269/problem/E 题意:给一个序列P1,P2,P3,P4....Pi,每次可以交换两个相邻的元素,执行最小次数的交换移动 ...

  9. codeforces 1282B2. K for the Price of One (Hard Version) (dp)

    链接 https://codeforces.com/contest/1282/problem/B2 题意: 商店买东西,商店有n个物品,每个物品有自己的价格,商店有个优惠活动,当你买恰好k个东西时可以 ...

  10. Codeforces 544E K Balanced Teams (DP)

    题目: You are a coach at your local university. There are nn students under your supervision, the prog ...

随机推荐

  1. 【MySQL学习杂记】 2017年7月13日

    1. 关于分组 当select使用groupby语法时,select返回字段集合里面除去 <使用了聚合函数的字段>.<不包含在 group by 子句的字段> 的其他字段,这些 ...

  2. css3实现 依次出现三个点(一般用于提示加载中。。。 提交中。。。)

    <a href="javascript:" class="login">登录中<span class="dotting"& ...

  3. Sequelize-nodejs-8-Transactions

    Transactions事务 Sequelize supports two ways of using transactions: Sequelize支持两种使用transactions的方法 One ...

  4. launch edge 和 latch edge 延迟

    本文转自 http://www.cnblogs.com/inet2012/archive/2012/03/07/2384149.html launch edge和latch edge分别是指一条路径的 ...

  5. java中的对象和类

    1.类:类是一个模板,它描述一类对象的行为和状态. 一个类可以包含以下类型变量: 局部变量:在方法.构造方法或者语句块中定义的变量被称为局部变量.变量声明和初始化都是在方法中,方法结束后,变量就会自动 ...

  6. composer install 失败,无法用 unzip 解压归档、proc_open() 函数未支持

    前言 记得最近好像有不只一个朋友问过 composer install 安装依赖时出现异常,导致项目无法运行.下面简单记录一下其中 2 个比较频繁问题的解决办法. 问题 & 解决 1.unzi ...

  7. office2010安装需MSXML版本6.10.1129.0详解解

    https://blog.csdn.net/qq_40824474/article/details/82390606 office2010安装提示报错 由于下列原因,安装程序无法继续,需要计算机安装M ...

  8. Android TV 全屏无标题

    想要全部窗口全屏无标题,修改 res\values\styles.xml 可设置主题和样式 <resources> <!-- Base application theme, depe ...

  9. 性能测试loadrunner安装

    把杀毒软件关闭 1. 点击 HP_LoadRunner_12.02_Community_Edition_T7177-15059.exe 完成后,点击下一步 接受协议 点击安装 点击完成 TOOLS - ...

  10. lua通用数据类型

    TValue结构 TValue这个结构体是Lua的通用结构体,,Lua中的所有的数据都可以使用这个结构体来表示.很容易想到,在面向对象中,这个结构体是一个基类,派生出来的都是其他的子类. TValue ...