B. String
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

One day in the IT lesson Anna and Maria learned about the lexicographic order.

String x is lexicographically less than string y, if either x is a prefix of y (and x ≠ y), or there exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi, and for any j (1 ≤ j < ixj = yj. Here |a| denotes the length of the string a. The lexicographic comparison of strings is implemented by operator < in modern programming languages​​.

The teacher gave Anna and Maria homework. She gave them a string of length n. They should write out all substrings of the given string, including the whole initial string, and the equal substrings (for example, one should write out the following substrings from the string "aab": "a", "a", "aa", "ab", "aab", "b"). The resulting strings should be sorted in the lexicographical order. The cunning teacher doesn't want to check all these strings. That's why she said to find only the k-th string from the list. Help Anna and Maria do the homework.

Input

The first line contains a non-empty string that only consists of small Latin letters ("a"-"z"), whose length does not exceed 105. The second line contains the only integer k (1 ≤ k ≤ 105).

Output

Print the string Anna and Maria need — the k-th (in the lexicographical order) substring of the given string. If the total number of substrings is less than k, print a string saying "No such line." (without the quotes).

Examples
input
aa
2
output
a
input
abc
5
output
bc
input
abab
7
output
b
Note

In the second sample before string "bc" follow strings "a", "ab", "abc", "b".

思路:优先队列;被c++卡死。。我是c++11过的

#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
#define true ture
#define false flase
using namespace std;
#define ll __int64
#define inf 0xfffffff
int scan()
{
int res = , ch ;
while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
{
if( ch == EOF ) return << ;
}
res = ch - '' ;
while( ( ch = getchar() ) >= '' && ch <= '' )
res = res * + ( ch - '' ) ;
return res ;
}
struct is
{
string a;
int st;
bool operator <(const is &x) const
{
return a>x.a;
}
};
string a;
int len;
priority_queue<is>q;
void k_big(int k)
{
is s;
for(ll i=;i<len;i++)
{
s.a=a[i];
s.st=i;
q.push(s);
}
while(!q.empty())
{
s=q.top();
//cout<<s.a<<" "<<s.st<<endl;
q.pop();
k--;
if(!k)
{
printf("%s\n",s.a.c_str());
return;
}
if(s.st<len-)
{
s.a+=a[++s.st];
q.push(s);
}
}
printf("No such line.\n");
}
int main()
{
int x,y,z,i,t;
cin>>a;
scanf("%d",&x);
len=a.size();
k_big(x);
return ;
}

Codeforces Beta Round #94 div2 D 优先队列的更多相关文章

  1. 图论/暴力 Codeforces Beta Round #94 (Div. 2 Only) B. Students and Shoelaces

    题目传送门 /* 图论/暴力:这是个连通的问题,每一次把所有度数为1的砍掉,把连接的点再砍掉,总之很神奇,不懂:) */ #include <cstdio> #include <cs ...

  2. BFS Codeforces Beta Round #94 (Div. 2 Only) C. Statues

    题目传送门 /* BFS:三维BFS,坐标再加上步数,能走一个点当这个地方在步数内不能落到.因为雕像最多8步就会全部下落, 只要撑过这个时间就能win,否则lose */ #include <c ...

  3. Codeforces Beta Round #73(Div2)

    A - Chord 题意:就是环中有12个字符,给你三个字符,判断他们之间的间隔,如果第一个和第二个间隔是3并且第二个和第三个间隔是4,那么就输出minor,如果第一个和第二个间隔是4并且第二个和第三 ...

  4. Codeforces Beta Round #94 (Div. 1 Only)B. String sam

    题意:给你一个字符串,找第k大的子字符串.(考虑相同的字符串) 题解:建sam,先预处理出每个节点的出现次数,然后处理出每个节点下面的出现次数,然后在dfs时判断一下往哪边走即可,注意一下num会爆i ...

  5. Codeforces Beta Round #94 div 1 D Numbers map+思路

    D. Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  6. Codeforces Beta Round #94 div 2 C Statues dfs或者bfs

    C. Statues time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  7. Codeforces Beta Round #94 div 2 B

    B. Students and Shoelaces time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  8. Codeforces Beta Round #107(Div2)

    B.Phone Numbers 思路:就是简单的结构体排序,只是这里有一个技巧,就是结构体存储的时候,直接存各种类型的电话的数量是多少就行,在读入电话的时候,既然号码是一定的,那么就直接按照格式%c读 ...

  9. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

随机推荐

  1. [LeetCode] 102. Binary Tree Level Order Traversal_Medium tag: BFS

    Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...

  2. Teleport Ultra 抓包工具

    Teleport Ultra 所能做的,不仅仅是离线浏览某个网页,它可以从 Internet 的任何地方抓回你想要的任何文件. 它可以在你指定的时间自动登录到你指定的网站下载你指定的内容,你还可以用它 ...

  3. vs2015 相关

    VS2015一共有3个版本,Visual Studio Community(社区版).Visual Studio Professional(专业版).Visual Studio Enterprise( ...

  4. Bagging Classifier+Regressor

    from sklearn.ensemble import BaggingRegressor Bagging通过引入随机化增大每个估计器之间的差异. 参数介绍: base_estimator:Objec ...

  5. iqueryable lambda表达式

    1.groupby 1.group by var newLaborDtos = laborDtos.GroupBy(s => new { s.FinancingAmount, s.Company ...

  6. 浏览器内核控制标签meta说明

    由于众所周知的原因,国内的主流浏览器都是双核浏览器:基于Webkit的内核用于常用网站的高速浏览,基于IE的内核主要用于部分网银.政府.办公系统等网站的正常使用.以360浏览器为例,我们优先通过Web ...

  7. 植物大战僵尸作弊器源代码(MFC版)

    控制版使用不太方便,此MFC版与控制台版内容一样.具体可以参考前面.此处只附源代码,不加以说明.......... 头文件 // jsMFCDlg.h : 头文件 // #pragma once // ...

  8. react脚手架构建工程

    https://blog.csdn.net/qtfying/article/details/78665664 第二步:安装less包: https://segmentfault.com/a/11900 ...

  9. MyEclipse 相关设置

    1. MyElipse复制项目后,修改项目的发布名称的方式.右击你的项目,选择 properties -- > MyElipse -- > web,然后修改名称即可. 2. IDE查看源代 ...

  10. idea生成springboot jpa的实体对象

    在idea的database里面添加上数据库 File-->Project Structure Modules--->点击加号----->选择JPA  选择确认之后再主面板上就会出现 ...