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原题 ...
随机推荐
- Vim 神器的打造方式
Vim 神器的打造方式 [字体:大 中 小] Vim 是一个上古神器,本篇文章主要持续总结使用 Vim 的过程中不得不了解的一些指令和注意事项,以及持续分享一个前端工作者不得不安装的一些插 ...
- hbase-1.2.5完全分布式部署
详细配置参考http://abloz.com/hbase/book.html#distributed ,2.2.2.2小节 1.修改hbase-site.xml文件.添加如下配置 cluster为ha ...
- 数据分析基础之Linalg的使用
Linear algebra 简介 When SciPy is built using the optimized ATLAS LAPACK and BLAS libraries, it has ve ...
- HDU4027 Can you answer these queries?(线段树 单点修改)
A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use ...
- Python pip 下载速度慢? Windows 设置 国内源,用 阿里云 国内镜像 加速
pip 提供了对 Python 包的查找.下载.安装.卸载的功能,是非常方便的 Python 包管理工具.但是,令人苦恼的是 pip 在国内的下载速度非常慢,速度常常只有每秒几十 K,甚至才几 K,小 ...
- 文本宽度的测量--measureText
HTML5中的canvas提供了文字宽度的测量方法: ctx.measureText(string).width var c=document.getElementById("myCanva ...
- HTML5 文件上传
这篇随笔主要引用https://juejin.im/post/59598ecf5188250d8d141fff,只用于自己学习,不对外宣传. FileList 对象和 file 对象 input[ty ...
- SQL注入详解
SQL是一种将SQL代码添加到输入参数中,传递到SQL服务器解析并执行的一种攻击手段 产生的原因 web开发人员无法保证所有输入都已经安全过滤 攻击者利用发送给SQL服务器的输入数据,构造可执行的SQ ...
- OpenCV二维Mat数组(二级指针)在CUDA中的使用
CUDA用于并行计算非常方便,但是GPU与CPU之间的交互,比如传递参数等相对麻烦一些.在写CUDA核函数的时候形参往往会有很多个,动辄达到10-20个,如果能够在CPU中提前把数据组织好,比如使用二 ...
- Codeforces 862A Mahmoud and Ehab and the MEX
传送门:CF-862A A. Mahmoud and Ehab and the MEX time limit per test 2 seconds memory limit per test 256 ...