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. python第二十二课——list函数

    演示list类型中常用的一些函数: 1.append(obj):将obj元素追加到列表的末尾 lt=['路费','佐罗','山治','乔巴','乌索普','纳米桑'] #append(): lt.ap ...

  2. 函数式编程的类型系统:typeclass--Functor的解释--构造类型

    函数式编程的类型系统:typeclass Typeclass是带有关联构造类型的抽象接口,抽象接口的行为用于约束构造类型. 构造类型实现了抽象接口的行为约束,就称这个实现为这个构造类型的函子. 要素: ...

  3. 2243. [SDOI2011]染色【树链剖分】

    Description 给定一棵有n个节点的无根树和m个操作,操作有2类: 1.将节点a到节点b路径上所有点都染成颜色c: 2.询问节点a到节点b路径上的颜色段数量(连续相同颜色被认为是同一段), 如 ...

  4. _viewstart.cshtml的作用

    在ASP.NET MVC 3.0及更高版本中,用Razor模板引擎新建项目后,Views目录下会出现一个这样的文件:_ViewStart.cshtml. _viewstart.cshtml的作用 1. ...

  5. Day15 集合(二)

    Set简介 定义 public interface Set<E> extends Collection<E> {} Set是一个继承于Collection的接口,即Set也是集 ...

  6. linux 安装git环境变量配置

    cd /usr/local mkdir git 源码安装 cd git yum install curl-devel expat-devel gettext-devel openssl-devel z ...

  7. Unity游戏开发之“分层碰撞”

    有没有同学遇到过这样的情况:在游戏开发3D游戏中非经常见,比方让一个物体能穿过一个物体 而还有一个物体不能穿过这个物体,并且3个物体都不能穿过地面.在unity中这样的情况的处理是通过分层碰撞来解决的 ...

  8. JavaScript-闭包函数(理解)

    JavaScript-闭包函数(理解) var foo = function (a) { return function inner () { console.log(a) } } var faa = ...

  9. rpm-yum_install_software

    rpm -ivh software_name安装软件 打印详情rpm -q software_name查询软件是否安装rpm -ql software_name查询安装目录rpm -e softwar ...

  10. kali linux修改更新源及更新

    1.修改sources.list源文件: leafpad /etc/apt/sources.list #aliyun 阿里云 deb http://mirrors.aliyun.com/kali ka ...