CS Round#49 C Max Substring
Max Substring
Memory limit: 256 MB
You are given a string S. Find a string T that has the most number of occurrences as a substring in S.
If the solution is not unique, you should find the one with maximum length. If the solution is still not unique, find the smallest lexicographical one.
Standard input
The first line contains string S.
Standard output
Print string T on the first line.
Constraints and notes
- SS consists of lowercase letters of the English alphabet
- The length of S is between 1 and 10^5
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100000+10
char s[MAXN];
int l,maxn=,maxl,last,ans=-,be,cnt[];
vector<int>pos[];
int main(){
scanf("%s",s);
l=strlen(s);
for(int i=;i<l;i++)cnt[s[i]-'a']++;
for(int i=;i<;i++)
maxn=max(maxn,cnt[i]);
for(int t=;t<;t++){
if(cnt[t]!=maxn)continue;
for(int i=;i<l;i++)
if(s[i]-'a'==t)pos[s[i]-'a'].push_back(i),last=i;
int maxlen=;
for(int k=;last+k<l;k++){
char r=s[pos[t][]+k];
bool flag=true;
for(int i=;i<pos[t].size();i++)
if(s[pos[t][i]+k]!=r){
flag=false;
break;
}
if(!flag)break;
maxlen++;
}
if(maxlen>ans){
ans=maxlen;
be=last;
}
}
for(int i=be;i<=be+ans;i++)putchar(s[i]);
return ;
}
CS Round#49 C Max Substring的更多相关文章
- 【CS Round 34】Max Or Subarray
[题目链接]:https://csacademy.com/contest/round-34/summary/ [题意] 让你找一个最短的连续子串; 使得这个子串里面所有数字or起来最大; [题解] 对 ...
- CodeForce Round#49 untitled (Hdu 5339)
Untitled Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- Codeforces Beta Round #49 (Div. 2)
Codeforces Beta Round #49 (Div. 2) http://codeforces.com/contest/53 A #include<bits/stdc++.h> ...
- Manacher BestCoder Round #49 ($) 1002 Three Palindromes
题目传送门 /* Manacher:该算法能求最长回文串,思路时依据回文半径p数组找到第一个和第三个会文串,然后暴力枚举判断是否存在中间的回文串 另外,在原字符串没啥用时可以直接覆盖,省去一个数组空间 ...
- 【CS round 34】Minimize Max Diff
[题目链接]:https://csacademy.com/contest/round-34/task/minimize-max-diff/ [题意] 给你n个数字; 数组按顺序不下降; 让你删掉k个数 ...
- Cs Round#56 D Find Path Union
题意:有一棵如下的完全二叉树,求所有给定结点到根节点的路径的并有多少条边. 一开始联想到线段树,发现结点的排布很像线段树的标号.于是模仿线段树敲了一下,交上去发现3个点MLE了... 无心优化,跑去看 ...
- Cs Round#54 E Late Edges
题意:给定一个无向图,你从结点1开始走,每经过一条边需要1的时间,每条边都有一个开放时间,只有当目前所用的时间大于等于开放时间时,这条边才可以被经过.每一单位时间你都必须经过一条边,问最快什么时候可以 ...
- CS Round#53 E Maxor
题意:给你N个数,你可以从中选出两个数将它们or起来得到M,求M的最大值及得到最大值的方案数. 刚了半个小时得到了一个貌似时O(N log max(Ai)^2)的方法,想了想发现貌似只能做出第一问,但 ...
- CS Round#53 C Histogram Partition
题意:给定一个数组A,以及一个初始值全为0的空数组B,每次可以对数组B的任意一个区间内的所有数+x,问至少几次操作能把B数组变成A数组 NOIP原题(积木大赛)升级版,话说CS怎么那么多跟NOIP原题 ...
随机推荐
- spark三种连接Join
本文主要介绍spark join相关操作. 讲述spark连接相关的三个方法join,left-outer-join,right-outer-join,在这之前,我们用hiveSQL先跑出了结果以方便 ...
- 最最简单的CentOs6在线源搭建
非常实用的在线源搭建,只要4步骤 1.点击进入http://mirrors.aliyun.com/repo/epel-6.repo ,这是阿里云的源 2.复制所有的代码 ctrl+a,ctrl+c ...
- 1.Introduction 介绍
Welcome to Log4j 2! Introduction Almost every large application includes its own logging or tracing ...
- Python中编码问题:u'\xe6\x97\xa0\xe5\x90\x8d' 类型的转为utf-8的解决办法
相信小伙伴们遇到过类似这样的问题,python2中各种头疼的转码,类似u'\xe6\x97\xa0\xe5\x90\x8d' 的编码,直接s.decode()是无法解决编码问题.尝试了无数办法,都无法 ...
- chrome Web开放 字体格式不能显示问题
/** * Chrome 32/33 webfont issue fix. * Requires jQuery. * More info: http://blog.cloudfour.com/chro ...
- 单元测试框架 unittest 的运行方法if __name__ == '__main__': unittest.main()
1. if __name__ == '__main__': unittest.main()2. 测试用例实例根据测试的特点分组在一起. unittest为此提供了一个机制:测试套件由unittest' ...
- 前后端分手大师——MVVM 模式
之前对 MVVM 模式一直只是模模糊糊的认识,正所谓没有实践就没有发言权,通过这两年对 Vue 框架的深入学习和项目实践,终于可以装B了有了拨开云雾见月明的感觉. 简而言之 Model–View–Vi ...
- java 内部类和闭包
内部类(inner class) public class Outer{ private String name; class Inner{ public String getOuterName(){ ...
- Spark之MapReduce原理
参考http://www.cnblogs.com/wuyudong/p/mapreduce-principle.html MapReduce 我们来拆开看: Mapping(映射)对集合里的每个目 ...
- Spring框架——后处理器
Bean的后处理 Spring容器实例化Bean实例之后进行的增强处理,关于这里的描述之前有点错误,现在来纠正一下:这个过程有点像AOP,不过我们知道AOP是对方法而言的,而Bean后处理器是针对Ja ...