aaa

· · 个人记录

#include<bits/stdc++.h>
using namespace std;
int n,a[2010];
stack<int> g;
queue<int> s;
int jb[2010];
//1为S,-1为G 
bool fd(int x){
    stack<int> st=g;
    while(!st.empty()){
        if(st.top()==x) return 1;
        st.pop();
    } 
    return 0;
}
bool fi(int x){
    queue<int> q=s;
    while(!q.empty()){
        if(q.front()==x) return 1;
        q.pop();
    }
    return 0;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=1;i<=2*n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=2*n;i++){
        if(a[i]>0) g.push(a[i]);
        else{
            bool f=0,ing=fd(-a[i]),ins=fi(-a[i]);
            if(!ing&&!ins){
                cout<<"*";
                return 0;
            }
            if(ins){
                if(s.front()!=-a[i]){
                    cout<<"*";
                    return 0;
                }
                else{
                    s.pop();
                    jb[-a[i]]=1;
                }
            }
            if(ing){
                while(!g.empty()){
                    if(g.top()==-a[i]){
                        g.pop();
                        break;
                    }
                    s.push(g.top());
                    g.pop();
                }
                jb[-a[i]]=-1;
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(jb[i]==1) cout<<"S";
        else cout<<"G";
    }
    return 0;
}