CF724D.Dense Subsequence

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a string s, consisting of lowercase English letters, and the integer m.

One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves.

Then one uses the chosen symbols to form a new string. All symbols from the chosen position should be used, but we are allowed to rearrange them in any order.

Formally, we choose a subsequence of indices 1 ≤ _i_1 < _i_2 < ... < i__t ≤ |s|. The selected sequence must meet the following condition: for every j such that 1 ≤ j ≤ |s| - m + 1, there must be at least one selected index that belongs to the segment [j,  j + m - 1], i.e. there should exist a k from 1 to t, such that j ≤ i__k ≤ j + m - 1.

Then we take any permutation p of the selected indices and form a new string _s__i__p_1_s__i__p_2... s__i__p__t.

Find the lexicographically smallest string, that can be obtained using this procedure.

给定一个由小写英文字母组成的字符串 $ s $ 和一个整数 $ m $。

你需要从该字符串中选择若干字符的位置(注意:选择的是位置,而非字符本身),使得字符串中任意长度为 $ m $ 的连续子段内至少包含一个被选中的位置。

随后,你使用所有被选中的位置上的字符来构造一个新的字符串。所有被选中的字符都必须使用,但你可以以任意顺序重新排列它们。

形式化地,我们选择一个下标子序列 $ 1 \leq i_1 < i_2 < \dots < i_t \leq |s| $。该被选子序列必须满足如下条件:对每个满足 $ 1 \leq j \leq |s| - m + 1 $ 的 $ j $,区间 $ [j,, j + m - 1] $ 内至少存在一个被选中的下标;即存在某个 $ k \in {1, 2, \dots, t} $,使得 $ j \leq i_k \leq j + m - 1 $。

接着,取被选下标的任意一个排列 $ p $,并构造新字符串 $ s_{i_{p_1}} s_{i_{p_2}} \dots s_{i_{p_t}} $。

请找出通过上述过程所能得到的字典序最小的字符串。

输入格式

The first line of the input contains a single integer m (1 ≤ m ≤ 100 000).

The second line contains the string s consisting of lowercase English letters. It is guaranteed that this string is non-empty and its length doesn't exceed 100 000. It is also guaranteed that the number m doesn't exceed the length of the string s.

输入的第一行包含一个整数 mm(1 ≤ m ≤ 100 0001 ≤ m ≤ 100\,000)。

第二行包含一个由小写英文字母组成的字符串 ss。保证该字符串非空,且其长度不超过 100 000100\,000。同时保证整数 mm 不超过字符串 ss 的长度。

输出格式

Print the single line containing the lexicographically smallest string, that can be obtained using the procedure described above.

输出一行,包含通过上述过程能得到的字典序最小的字符串。

输入输出样例

  • 输入#1

    3
    cbabc

    输出#1

    a
  • 输入#2

    2
    abcab

    输出#2

    aab
  • 输入#3

    3
    bcabcbaccba

    输出#3

    aaabb

说明/提示

In the first sample, one can choose the subsequence {3} and form a string "a".

In the second sample, one can choose the subsequence {1, 2, 4} (symbols on this positions are 'a', 'b' and 'a') and rearrange the chosen symbols to form a string "aab".

在第一个样例中,可以选择子序列 {3}\{3\},并构成字符串 "a"。

在第二个样例中,可以选择子序列 {1, 2, 4}\{1,\,2,\,4\}(这些位置上的字符分别为 'a'、'b' 和 'a'),并将所选字符重新排列,构成字符串 "aab"。

输入解题思路,AI测评打分。不知道怎么写?

首页