QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#367988#8509. Expanding STACKS!ucup-team1196#RE 0ms3604kbC++233.1kb2024-03-26 17:54:542024-03-26 17:54:54

Judging History

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

  • [2024-03-26 17:54:54]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3604kb
  • [2024-03-26 17:54:54]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#define int long long

#define pii pair<int, int>
string check(int n, vector<int> &a) {
    std::vector<int> in(n + 1), out(n + 1);
    for (int i = 1; i <= 2 * n; i++) {
        if (a[i] > 0) in[a[i]] = i;
        if (a[i] < 0) out[-a[i]] = i;
    }
    std::vector<int> q1, q2;
    std::vector<int> ans(n + 1);
    for (int i = 1; i <= 2 * n; i++) {
        int x = a[i];
        if (x > 0) {
            if (q1.size() && q2.size() && out[q1.back()] < out[q2.back()] && out[x] < out[q1.back()]) {
                q1.push_back(x);
                ans[x] = 1;
            } else if (q1.size() && q2.size() && out[q1.back()] > out[q2.back()] && out[x] < out[q2.back()]) {
                q2.push_back(x);
                ans[x] = 2;
            } else if (q1.size() && out[q1.back()] > out[x]) {
                q1.push_back(x);
                ans[x] = 1;
            } else if (q2.size() && out[q2.back()] > out[x]) {
                q2.push_back(x);
                ans[x] = 2;
            } else if (q1.size() == 0) {
                q1.push_back(x);
                ans[x] = 1;
            } else if (q2.size() == 0) {
                q2.push_back(x);
                ans[x] = 2;
            } else {
                return "*";
            }
        } else {
            x = -x;
            if (q1.size() && q1.back() == x) {
                q1.pop_back();
            } else if (q2.size() && q2.back() == x) {
                q2.pop_back();
            } else {
                return "*";
            }
        }
    }
    string t = "";
    for (int i = 1; i <= n; i++) {
        t += "GS"[ans[i] - 1];
    }
    return t;
}
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), q1(n + 1), q2(n + 1);
    map<int, int> mp, is;
    std::vector<int> ans(n + 1);
    priority_queue<pii> hp1, hp2;
    for (int i = 1; i <= 2 * n; i++) {
        std::cin >> a[i];
    }
    for (int i = 1; i <= 2 * n; i++) {
        if(hp2.size() == 1) {
            auto [id, x] = hp2.top();
            hp1.push({id, x});
            is[x] = 2;
            hp2.pop();
        }
        if(a[i] > 0) {
            hp1.push({i, a[i]});
            is[a[i]] = 1;
        } else {
            int y = a[i] * -1;
            if(is[y] == 1) {
                while(hp1.size()) {
                    auto [id, x] = hp1.top();
                    hp1.pop();
                    if(x != y) {
                        hp2.push({id, x});
                        is[x] = 2;
                    } else {
                        ans[y] = is[x];
                        break;
                    }
                }
            } else {
                if(hp2.top().second == y) {
                    hp2.pop();
                    ans[y] = 2;
                } else {
                    cout << check(n, a);
                    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: 3552kb

input:

2
+2 +1 -1 -2

output:

GG

result:

ok correct

Test #2:

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

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: 3540kb

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: 0
Accepted
time: 0ms
memory: 3560kb

input:

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

output:

GGGGGGGGGS

result:

ok correct

Test #6:

score: -100
Runtime Error

input:

42
+26 -26 +12 +8 -12 -8 +30 +5 +22 +3 -3 +2 -30 +10 -10 -2 -22 +23 +39 -39 +17 -17 -23 +38 +24 -24 +27 +29 -29 -27 -38 -5 +37 -37 +21 +16 +28 -28 +6 +40 +14 +19 -19 -14 +11 +35 -35 -11 +4 +25 -25 -4 -40 -6 +13 +20 +1 -1 +33 +34 +7 -7 -34 +41 -41 +36 +31 -31 -36 +42 +32 -32 +15 +18 -18 -15 +9 -9 -42...

output:


result: