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:核心思想与源码分析> ...
随机推荐
- js 全局变量和局部变量
Javascript在执行前会对整个脚本文件的声明部分做完整分析(包括局部变量),但是不能对变量定义做提前解析 1.作用域和作用域链 2.变量声明提前
- Python全栈(一)编程语言介绍
一.编程语言介绍 程序是计算机能读懂的语言,是人和计算机沟通的方式. 计算机无法理解符号,只能理解0,1的二进制. 计算机内的运行状态就像灯泡的开关一样来表示各庄状态,两个灯泡能表示4种状态,无数的灯 ...
- Linux利用OneinStack搭建环境
OneinStack官方网站:https://oneinstack.com 介绍 OneinStack支持以下数种环境组合: LNMP(Linux + Nginx+ MySQL+ PHP) LAMP( ...
- 孤荷凌寒自学python第六十三天学习mongoDB的基本操作并进行简单封装2
孤荷凌寒自学python第六十三天学习mongoDB的基本操作并进行简单封装2 (完整学习过程屏幕记录视频地址在文末) 今天是学习mongoDB数据库的第九天. 今天继续学习mongoDB的简单操作, ...
- 聊聊、AES 和 DES
AES 和 DES 都是对称加密的一种,但是 DES 的 Key 是 56 位,而 AES 的 Key 有 128,256,512 可选. AES 加密AES String randomKey = & ...
- vmware中桥接丶仅主机丶net模式的区别
VMWare提供三种工作模式桥接(bridge).NAT(网络地址转换)和host-only(主机模式). 桥接模式 在桥接模式下,VMWare虚拟出来的操作系统就像是局域网中的一台独立的主机(主机和 ...
- Git 提交修改
今天发现前几天的某一个提交因为忽略文件的问题而导致有几个文件没有提交,需要修改一下某个提交,研究一下可以用rebase命令来完成,执行过程模拟如下: 1. 环境搭建,版本库如下: 文件目录如下: 假设 ...
- HTML5_纯JS实现上传文件显示文件大小,文件信息,上传进度_不使用JS库
前台 html <input type="file" id="_netLogo" onchange="fileSelected();" ...
- 如何实现自己的Android MVP框架?
相信熟悉android开发的童鞋对MVP框架应该都不陌生吧,网上很多关于android中实现MVP的文章,大家可以直接搜索学习.这些文章中,MVP的实现思路基本都是把Activity.Fragment ...
- POJ 2115 C-Looooops | exgcd
题目 给出一个循环for(int i=A;i!=B;i+=C) 在mod (1<<k) 下是否可以退出循环 是,输出时间,否输出FORVEER 题解: 题意可以变换成 A+Cx=B (mo ...