AtCoder - 4130 K-th Substring
Problem Statement
You are given a string s. Among the different substrings of s, print the K-th lexicographically smallest one.
A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = ababc
, a
, bab
and ababc
are substrings of s, while ac
, z
and an empty string are not. Also, we say that substrings are different when they are different as strings.
Let X=x1x2…xn and Y=y1y2…ym be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or xj>yj where j is the smallest integer such that xj≠yj.
Constraints
- 1 ≤ |s| ≤ 5000
- s consists of lowercase English letters.
- 1 ≤ K ≤ 5
- s has at least K different substrings.
Partial Score
- 200 points will be awarded as a partial score for passing the test set satisfying |s| ≤ 50.
Input
Input is given from Standard Input in the following format:
s
K
Output
Print the K-th lexicographically smallest substring of K.
Sample Input 1
aba
4
Sample Output 1
b
s has five substrings: a
, b
, ab
, ba
and aba
. Among them, we should print the fourth smallest one, b
. Note that we do not count a
twice.
Sample Input 2
atcoderandatcodeer
5
Sample Output 2
andat
Sample Input 3
z
1
Sample Output 3
z 一看这种题第一反应:裸上SAM啊!
但是一看数据范围:艹这是连SAM都不用的傻逼题了。
因为字典序第K小肯定不会超过K位,所以直接暴力+去重就可以做了QWQ
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=5005;
string ch[maxn*6];
char s[maxn];
int n,k,cnt;
int main(){
scanf("%s%d",s,&k),n=strlen(s);
for(int i=0,T;i<n;i++){
ch[++cnt]=s[i];
T=min(k,n-i);
for(int j=1;j<T;j++,cnt++) ch[cnt+1]=ch[cnt]+s[i+j];
} sort(ch+1,ch+cnt+1);
unique(ch+1,ch+cnt+1);
cout<<ch[k]<<endl;
return 0;
}
AtCoder - 4130 K-th Substring的更多相关文章
- AtCoder Beginner Contest 043 D - アンバランス / Unbalanced
题目链接:http://abc043.contest.atcoder.jp/tasks/arc059_b Time limit : 2sec / Memory limit : 256MB Score ...
- LeetCode第[5]题(Java):Longest Palindromic Substring 标签:String、动态规划
题目中文:求最长回文子串 题目难度:Medium 题目内容: Given a string s, find the longest palindromic substring in s. You ma ...
- sql 取汉字首字母
)) ) --用于加密 --WITH ENCRYPTION as begin declare @intLen int ) ) set @intLen = len(@str) set @strRet = ...
- sql 函数 汉字转拼音
GO /****** Object: UserDefinedFunction [dbo].[fn_GetPy] Script Date: 2017/1/4 10:53:49 ******/ SET A ...
- Pjax调用
$.pjax({container:'#content_center',url:href,data:data}); $(document).on('pjax:send', function() {// ...
- 都别说工资低了,我们来一起写简单的dom选择器吧!
前言 我师父(http://www.cnblogs.com/aaronjs/)说应当阅读框架(jquery),所以老夫就准备开始看了 然后公司的师兄原来写了个dom选择器,感觉不错啊!!!原来自己从来 ...
- Leetcode: Encode String with Shortest Length && G面经
Given a non-empty string, encode the string such that its encoded length is the shortest. The encodi ...
- JAVA时间格式转换大全
import java.text.*; import java.util.Calendar; public class VeDate { /** * 获取现在时间 * * @return 返回时间类型 ...
- Spark中常用工具类Utils的简明介绍
<深入理解Spark:核心思想与源码分析>一书前言的内容请看链接<深入理解SPARK:核心思想与源码分析>一书正式出版上市 <深入理解Spark:核心思想与源码分析> ...
随机推荐
- sources-t.list
deb http://debian.ustc.edu.cn/ubuntu/ trusty main multiverse restricted universe deb http://debian.u ...
- 带外键Mysql
带外键的表格的查询 复制代码 //////////////////查询指定表外键约束 select a.name as 约束名, object_name(b.parent_object_id) as ...
- ssh 免交互登录 ,远程执行命令脚本。
##免交互SSH登录auto_login_ssh () { expect -c "set timeout -1; spawn -noecho ssh -o ...
- JavaWeb笔记(三)HTTP
常见请求头 User-Agent:浏览器版本信息,可以解决浏览器兼容性问题 Referer:请求来源地址,可以防盗链和统计 Request 方法 获取请求方式: String getMethod() ...
- Scala 基础(1)—— 定义变量 & 定义函数
1. 使用 val & var 定义变量 Scala 中的变量被分为2种:val 和 var.其含义于 Java 中的 final 关键字类似. val 等同于被 final 修饰过的变量, ...
- android中常见的Drawable资源有哪些?
Drawable资源是安卓应用中最常见的一种资源,比如图片等,因此,对于初学者而言,必须掌握drawable资源相关应用. 今天在网上刚好看到了一篇介绍android Drawable资源的文章,分享 ...
- hdu 2544 最短路 (最短路径)
最短路 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- LeetCode -- Product of Array Except Self My Submissions Question
Question: Given an array of n integers where n > 1, nums, return an array output such that output ...
- 应用交付工程师Troubleshooting经验分享
应用交付工程师Troubleshooting经验分享 来源:http://blog.51cto.com/virtualadc/1188328 来源:http://blog.51cto.com/virt ...
- POJ 1375 Intervals | 解析几何
参考了这个博客 #include<cstdio> #include<algorithm> #include<cstring> #include<cmath&g ...