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原题 ...
随机推荐
- RabbitMQ-客户端
Install-Package RabbitMQ.Client 参考: http://www.rabbitmq.com/download.html https://www.nuget.org/pack ...
- Hat's Fibonacci
Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequen ...
- setup 命令中防火墙配置选项无法打开
故障提示 1.1 如何让setup 命令中防火墙配置生效 1.1.1 CentOS系统找不到setup命令工具的解决方法 yum -y install setuptool #安装setup命令工具 y ...
- ssh: connect to host master port 22: Connection refused
hadoop集群启动的时候namenode显示Connection refused 到windows下ping master 显示传输中过期 ip是静态的 ssh master 也是连接拒绝 重启s ...
- AngularJS学习篇(十六)
AngularJS 表单 HTML 控件 以下 HTML input 元素被称为 HTML 控件: input 元素 select 元素 button 元素 textarea 元素 HTML 表单 H ...
- js实现查找字符串中最多的字符的个数
用hash table实现.key是字符,value是字符个数. var hashTable={}; var str="fjsdeiuwidshjfhjsksghfjhsjjskalsk&q ...
- scroll 区域滚动
网页内都有快速滚动和回弹的效果: overflow: scroll; -webkit-overflow-scrolling: touch; 实际上,Safari用了原生控件来实现,对于有-webk ...
- PostgreSQL 下生成 UUID(Guid)
最近在Windows 10 下安装了 PostgreSQL(postgresql-9.6.3-1-windows.exe),在学习过程中,发现PostgreSQL 支持UUID(Guid)类型,但是却 ...
- EF分页
先来看看几个LINQ to SQL的几个函数. Take 说明:获取集合的前n个元素:延迟.即只返回限定数量的结果集. var q = ( from e in db.Employees order ...
- C语言一些知识点回顾
1.多行宏定义 #include <stdio.h> #define _PyObject_HEAD_EXTRA \ struct _object *_ob_next; \ struct _ ...