Codeforces —— String(128B)


input

aa
2

output

a

input

abc
5

output

bc

input

abab
7

output

b

题意

给定s,输出其字典序第k小的子串

思路

首先将单个字符放入multiset中,之后每次向后扩展新的子串放入multiset(使用优先队列莫名其妙会TLE……)后在进行选择,直到找到第k大的子串

代码

#pragma GCC optimize(2)
#include<iostream>
#include<unordered_map>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<set>
#define Buff ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define rush() int Case = 0; int T; cin >> T;  while(T--)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define per(i, a, b) for(int i = a; i >= b; i --)
#define reps(i, a, b) for(int i = a; b; i ++)
#define clc(a, b) memset(a, b, sizeof(a))
#define Buff ios::sync_with_stdio(false)
#define readl(a) scanf("%lld", &a)
#define readd(a) scanf("%lf", &a)
#define readc(a) scanf("%c", &a)
#define reads(a) scanf("%s", a)
#define read(a) scanf("%d", &a)
#define lowbit(n) (n&(-n))
#define pb push_back
#define sqr(x) x*x
#define lson rt<<1
#define rson rt<<1|1
#define ls lson, l, mid
#define rs rson, mid+1, r
#define y second
#define x first
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int>PII;
const int mod = 1e9+7;
const double eps = 1e-6;
const int N = 1e6+7;
string s, t;
struct node
{
    string s;
    int id;
    bool operator<(node a)const
    {
        return s < a.s;
    }
}res;
multiset<node> se;

int main()
{
    int k, n;
    cin >> s >> k;
    n = s.size();
    reps(i, 0, s[i])
    {
        res.s = s[i]; res.id = i+1;
        se.insert(res);
    }
    int tot = 0;
    while(se.size())
    {
        auto it = se.begin();
        res = *it;
        se.erase(it);
        tot ++;
        if(tot == k)    break;
        if(res.id < n)
        {
            t = res.s;
            t += s[res.id];
            se.insert({t, res.id+1});
        }
    }
    if(tot == k)    cout << res.s <<endl;
    else            puts("No such line.");
	return 0;
}
posted @ 2020-10-20 02:10  youngman-f  阅读(56)  评论(0编辑  收藏  举报