提交时间:2022-07-13 11:48:58

运行 ID: 51510

#include<bits/stdc++.h> #define int long long using namespace std; inline int read(){ int x=0,f=1; char c=getchar(); while(!isdigit(c)){if(!(c^'-'))f=-1;c=getchar();} while(isdigit(c)){x=((x<<1)+(x<<3)+(c^48));c=getchar();} return x*f; } int n,k,t,z[15],maxx=-1; string s; vector<char>now; signed main(){ n=read(),k=read(),t=read(); cin>>s; for(int i=0;i<s.size();i++)z[s[i]-96]++,maxx=max(maxx,z[s[i]-96]); now.push_back(s[0]); for(int i=1;i<s.size();i++){ int x=-1; if(s[i]^s[i-1]){ for(int j=i-1;j>=0;j--){ if(!(s[j]^s[i])){x=j;break;} } } if(!(x^-1))now.push_back(s[i]); else if(!((i-x)^1)&&s[i]>s[x])now.pop_back(),now.push_back(s[i]); } cout<<now.size()<<endl; if(t^0)for(int i=0;i<now.size();i++)putchar(now[i]); puts(""); return 0; }