30pts 求助神秘输出
查看原帖
30pts 求助神秘输出
663195
Z_AuTwT楼主2024/8/28 13:56

rt

#include<bits/stdc++.h>
using namespace std;
int stk[100010],STK[100010];
int Arr[1010];
char Ans[2010];
int Max[1010];
int tot,Tot;
main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>Arr[i];
    for(int i=n;i>=1;i--) Max[i]=max(Max[i+1],Arr[i]);
    stk[tot]=STK[Tot]=1e9;
    int cnt=0,Cnt=1;
    for(int i=1;i<=n;i++){
        if(Arr[i]<stk[tot]&&!(Arr[i]<STK[Tot]&&Max[i+1]>Arr[i]&&Max[i+1]>STK[Tot])){
            Ans[++cnt]='a';
            stk[++tot]=Arr[i];
        }else{
            while(stk[tot]==Cnt&&tot){
                tot--;
                Cnt++;
                Ans[++cnt]='b';
            }
            if(Arr[i]<stk[tot]&&!(Arr[i]<STK[Tot]&&Max[i+1]>Arr[i]&&Max[i+1]>STK[Tot])){
                Ans[++cnt]='a';
                stk[++tot]=Arr[i];
            }else{
                if(Arr[i]<STK[Tot]){
                    Ans[++cnt]='c';
                    STK[++Tot]=Arr[i];
                }else{
                    while(STK[Tot]==Cnt&&Tot){
                        Tot--;
                        Cnt++;
                        Ans[++cnt]='d';
                    }
                    if(Arr[i]<STK[Tot]){
                        Ans[++cnt]='c';
                        STK[++Tot]=Arr[i];
                    }else{
                        cout<<0<<"\n";
                        return 0;
                    }
                }
            }
        }
    	while(stk[tot]==Cnt&&tot){
            tot--;
            Cnt++;
            Ans[++cnt]='b';
        }
        while(STK[Tot]==Cnt&&Tot){
            Tot--;
            Cnt++;
            Ans[++cnt]='d';
        }
    }
    while(tot){
		Ans[++cnt]='b';
		tot--;
	}
	while(Tot){
		Ans[++cnt]='d';
		Tot--;
	}
    for(int i=1;i<=cnt;i++) cout<<Ans[i]<<" ";
}
2024/8/28 13:56
加载中...