Codeforces Round #617 (Div. 3) E1

E1. String Coloring (easy version)

观察样例我们发现要是最长下降子序列要是>=3 那我们显然不可能有解
然后我们考虑构造
要是最长最长下降子序列只是2的话 那显然我们只需要让在后面的比较小的值
也就是下降子序列的第二个位置变成1 其他位置都是0 即可

#include <bits/stdc++.h>
using namespace std;
const int N = 3e5+10;
const int M = 998244353;
const int mod = 998244353;
#define int long long
int up(int a,int b){return a<0?a/b:(a+b-1)/b;}
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define _ 0
#define pi acos(-1)
#define INF 0x3f3f3f3f3f3f3f3f
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);

void solve(){
    int n;cin>>n;
    string a;cin>>a;
    vector<int>f;
    for(int i=0;i<n;i++){
        if(lower_bound(f.begin(),f.end(),a[i],greater<>())==f.end())f.push_back(a[i]);
        else f[lower_bound(f.begin(),f.end(),a[i],greater<>())-f.begin()]=a[i];
    }
    if(f.size()>=3){NO return;}else YES
    for(int i=0;i<n;i++){
        for(int j=i;j>=0;j--){
            if(a[j]>a[i]){
                cout<<1;
                goto out;
            }
        }
        cout<<0;
        out:1;
    }
}
signed main(){
    fast
    int t;t=1;//cin>>t;
    while(t--) {
        solve();
    }
    return ~~(0^_^0);
}
posted @ 2022-10-31 20:51  ycllz  阅读(15)  评论(0)    收藏  举报