-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcf_2200_lex_minstr.cpp
68 lines (67 loc) · 1.16 KB
/
cf_2200_lex_minstr.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main(void){
// Your code here!
int n,k;
cin>>n>>k;
string s;
cin>>s;
int ind = 2;
int st = -1;
int len = 0;
int i = 0;
while(i<n-1 && s[i]==s[i+1])
{
i++;
len++;
}
i++;
len++;
for(;i<n;i++)
{
if(s[i]>s[0])
{
break;
}
if(st!=-1)
{
if(s[i]<s[st])
{
len = i+1;
st = -1;
}
else if(s[i]>s[st])
{
break;
}
else
{
st++;
if(st==len)
st = 0;
}
continue;
}
if(s[i]==s[0])
{
st = 1;
len = i;
continue;
}
len = i + 1;
}
string ans = "";
// if(k==29140)
// {
// cout<<len<<'-'<<i<<s[i]<<st<<s[st];
// //cout<<s<<"\n\n";
// }
s = s.substr(0,len);
while(ans.length()<k)
{
ans=ans.append(s);
}
ans = ans.substr(0,k);
cout<<ans;
}