QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#367901#8509. Expanding STACKS!ucup-team1196#WA 0ms3616kbC++231.6kb2024-03-26 16:30:242024-03-26 16:30:25

Judging History

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

  • [2024-03-26 16:30:25]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3616kb
  • [2024-03-26 16:30:24]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#define int long long

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    std::cin >> n;
    std::vector<int> a(2 * n + 1), in(n + 1), out(n + 1);
    std::stack<int> q1, q2;
    map<int, int> mp, is;
    std::vector<int> ans(n + 1);
    for (int i = 1; i <= 2 * n; i++) {
        std::cin >> a[i];
    }
    for (int i = 1; i <= 2 * n; i++) {
        if(a[i] > 0) {
            q1.push(a[i]);
            is[a[i]] = 1;
        } else {
            a[i] *= -1;
            is[i] = 0;
            if(!is[a[i]]) {
                cout << "*\n";
                return 0;
            }
            if(!mp.count(a[i])) {
                int x = 0;
                stack<int> s;
                while(q1.size()) {
                    x = q1.top(); q1.pop();
                    if(x != a[i]) {
                        s.push(x);
                        mp[x] = 1;
                    } else {
                        break;
                    }
                }
                while(s.size()) {
                    x = s.top();
                    s.pop();
                    q2.push(x);
                }
            } else {
                if(q2.top() == a[i]) {
                    q2.pop();
                    ans[a[i]] = 1;
                } else {
                    cout << "*\n";
                    return 0;
                }
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        std::cout << "GS"[ans[i]];
    }
    std::cout << "\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
+2 +1 -1 -2

output:

GG

result:

ok correct

Test #2:

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

input:

2
+1 +2 -1 -2

output:

GS

result:

ok correct

Test #3:

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

input:

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

output:

*

result:

ok correct

Test #4:

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

input:

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

output:

*

result:

wrong answer team and jury output doesn't agree on whether there's an assignment