麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

【Codeforces 724 D Dense Subsequence】+ 貪心

2019-11-11 04:46:24
字體:
來源:轉載
供稿:網友

D. Dense Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

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?≤?i1?<?i2?<?…?<?it?≤?|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?≤?ik?≤?j?+?m?-?1.

Then we take any permutation p of the selected indices and form a new string sip1sip2… sipt.

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

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. Output

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

3 cbabc

Output

a

Input

2 abcab

Output

aab

Input

3 bcabcbaccba

Output

aaabb

Note

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”.

貪心,在[l + 1, l +m-1]里選出最小,字典序最下,把比選中的最大的字符小的都加上?

AC代碼:

#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int K = 1e5 + 10;bool vis[K];char s[K],st[K],ss ='a';int main(){ int N; scanf("%d %s",&N,s); int nl = strlen(s),pl = 0,kl = 0; while(pl + N - 1 < nl){ int ml = pl; for(int i = pl; i <= pl + N - 1; i++) if(s[i] <= s[ml]) ml = i; st[++kl] = s[ml],ss = max(ss,s[ml]),pl = ml + 1,vis[ml] = 1; } for(int i = 0 ; i < nl ; i++) if(!vis[i] && s[i] < ss) st[++kl] = s[i]; sort(st + 1, st + 1 + kl); printf("%s/n",st + 1); return 0;}
上一篇:雙向鏈表

下一篇:動態鏈接庫dll的調用

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 中文字幕一区久久 | 免费网站看v片在线a | 色999久久久精品人人澡69 | 99欧美视频 | 91麻豆精品国产91久久久无需广告 | 久久综合九色综合久久久精品综合 | 北原夏美av| 欧美精选一区二区 | 国产欧美日韩在线不卡第一页 | 最新福利在线 | 中文字幕亚洲一区二区三区 | 国产日韩在线观看一区 | 黄色片免费在线 | 国产精品99久久99久久久二 | 成人毛片在线 | 一区二区三区精品国产 | 国产精品视频不卡 | 国产日韩欧美 | 久久久鲁 | 19禁国产精品福利视频 | 校花被肉干高h潮不断 | 日韩精品中文字幕一区二区三区 | 毛片一级视频 | 中国嫩模一级毛片 | 91成人免费 | 国产色片在线观看 | 久久久青青草 | www视频免费在线观看 | 鲁久久 | 202z中文字幕第一页 | 男女一边摸一边做羞羞视频免费 | 国产精品99一区二区 | 精品国产一区二区三区在线观看 | 2021国产精品| 黄色网欧美 | 久草在线网址 | 国产羞羞视频在线观看免费应用 | 免费在线观看成人网 | 免费高清一级欧美片在线观看 | 国产1区在线观看 | 亚洲成人久久精品 |