QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#380463#8509. Expanding STACKS!Jose_17WA 0ms3828kbC++201.4kb2024-04-07 04:20:312024-04-07 04:20:33

Judging History

你现在查看的是最新测评结果

  • [2024-04-07 04:20:33]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3828kb
  • [2024-04-07 04:20:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
void solve(){
    int n;
    cin>>n;
    stack<int> pila[2];
    vector<pair<char,int> > elementos(2 * n + 1);
    vector<int> inicios(n + 1);
    vector<int> extremo(2 * n + 1);
    for(int i = 1;i <= 2 * n; i++){
        cin>>elementos[i].first>>elementos[i].second;
        if(elementos[i].first =='+') inicios[elementos[i].second] = i;
        else{
            extremo[inicios[elementos[i].second]] = i;
            extremo[i] = inicios[elementos[i].second];
        }
    }
    vector<char> respuesta;
    for(int i = 1; i <= 2 * n; i++){
        while(!pila[0].empty() && pila[0].top() < i) pila[0].pop();
        while(!pila[1].empty() && pila[1].top() < i) pila[1].pop();
        if(elementos[i].first == '+'){
            if(pila[0].empty() || pila[0].top() > extremo[i]){
                respuesta.push_back('G');
                pila[0].push(extremo[i]);
            }else if(pila[1].empty() || pila[1].top() > extremo[i]){
                respuesta.push_back('S');
                pila[1].push(extremo[i]);
            }else{
                cout<<"*\n";
                return;
            }
        }
    }
    for(int i = 0; i < n; i++) cout<<respuesta[i];
    cout<<"\n";
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3544kb

input:

2
+2 +1 -1 -2

output:

GG

result:

ok correct

Test #2:

score: 0
Accepted
time: 0ms
memory: 3828kb

input:

2
+1 +2 -1 -2

output:

GS

result:

ok correct

Test #3:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

3
+1 +2 +3 -1 -2 -3

output:

*

result:

ok correct

Test #4:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

10
+3 -3 +4 -4 +6 +2 -2 -6 +7 -7 +5 -5 +10 +1 +9 +8 -8 -9 -1 -10

output:

GGGGGGGGGG

result:

ok correct

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3484kb

input:

10
+8 -8 +2 +10 -2 -10 +7 -7 +1 -1 +6 -6 +5 +3 +4 +9 -9 -4 -3 -5

output:

GGSGGGGGGG

result:

wrong answer client leaving is not the top of its stack