提交时间:2022-07-13 11:49:05
运行 ID: 51512
#include <bits/stdc++.h> using namespace std; int n,k,type,d,ai[510000],num,ctn[51000],ans=0; string a; int main() { // freopen ("seq.in","r",stdin); // freopen ("seq.out","w",stdout); cin>>n>>k>>type; cin>>a; d=a[n-1],num=n-1; for (int i=n-2; i>=0; i--) if (a[i]==d) ctn[i]=-1,ctn[num]++; else d=a[i],num=i; for (int i=0; i<=n-1; i++) for (int j=0; j<=n-1; j++) if (a[j]==a[i] && ctn[j]!=-1 && ctn[i]!=-1 &&i!=j) if (ctn[i]>ctn[j]) ctn[j]=-1; else if (ctn[i]<ctn[j]) ctn[i]=-1; else if (a[i]<a[i+1]) ctn[j]=-1; else ctn[i]=-1; for (int i=1; i<=n; i++) if (ctn[i-1]!=-1) ans+=ctn[i-1]+1; cout<<ans<<endl; if (type!=0) for (int i=1; i<=n; i++) if (ctn[i-1]!=-1) for (int j=1; j<=ctn[i-1]+1; j++)cout<<a[i-1]; return 0; }