[栈,模拟] Codeforces Round #679 (Div. 2, based on Technocup 2021 Elimination Round 1) D. Shurikens

题目:http://codeforces.com/contest/1435/problem/D

要是当时看看这个D题就好了,血亏

简单的用栈模拟即可

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define V vector
#define pb push_back
int main(){
    ios::sync_with_stdio(0);
    ll n;
    cin>>n;
    ll id=0;
    stack<ll> st;
    V<ll> ans(2*n+1);

    ll f=1;
    rep(cas,1,2*n){
        char in;
        cin>>in;
        if(in=='+'){
            st.push(++id);
        }
        else{
            ll nn;
            cin>>nn;
            if(st.size()==0){
                f=0;
                continue;
            }
            ll now=st.top();st.pop();
            ans[now]=nn;
            if(now<n){
                if(ans[now]<ans[now+1])f=0;
            }
        }
    }
    if(f){
        cout<<"YES"<<endl;
        rep(i,1,n)cout<<ans[i]<<' ';
        cout<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}

 

posted @ 2020-10-26 20:03  Railgun000  阅读(146)  评论(0编辑  收藏  举报