显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn=300010;
char s[maxn];int len;
int main(){
freopen("MinRepresentations.in","r",stdin);
freopen("MinRepresentations.out","w",stdout);
scanf("%d%s",&len,s+1);
int p1=1,p2=2,k;s[len+1]='z'+1;
while(p1<=len&&p2<=len){k=0;
while(s[p1+k]==s[p2+k])++k;
if(s[p1+k]<s[p2+k]){
p2=p2+k+1;
p2+=p1==p2;
}
else{
p1=p1+k+1;
p1+=p1==p2;
}
}
p1=p1<=len?p1:p2;
for(int i=p1;i<=len;i++)
putchar(s[i]);
for(int i=1;i<p1;i++)
putchar(s[i]);
printf("\n");
return 0;
}