标签:int char ring 字典序 tps eof c++ ble ref
#include <bits/stdc++.h>
using namespace std;
char a[1000010];
int res[1000010];
int main()
{
int n;
string s;
int ct = 1;
cin >> n >> s;
memset(a,‘a‘,sizeof a);
for (int i = 0 ; i < n ; i ++ )
{
for (int j = 1 ; j <= ct ; j ++ )
{
if(s[i] >= a[j])
{
a[j] = s[i];
res[i] = j;
break;
}
if(j == ct && s[i] < a[j])
{
ct ++ ;
a[j+1] = s[i];
res[i] = ct;
}
}
}
cout << ct << endl;
for (int i = 0 ; i < n ; i ++ ) cout << res[i] << " ";
return 0;
}
标签:int char ring 字典序 tps eof c++ ble ref
原文地址:https://www.cnblogs.com/QFNU-ACM/p/12956460.html