其他分享
首页 > 其他分享> > 5.25每日一题题解

5.25每日一题题解

作者:互联网

E2 - String Coloring (hard version)

涉及知识点:

solution:

std:

#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;
}

标签:1000010,int,题解,每日,++,5.25,res,E2,ct
来源: https://www.cnblogs.com/QFNU-ACM/p/12956460.html