QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#63926#5108. Prehistoric ProgramsNoobie_99WA 16ms6168kbC++201.6kb2022-11-23 18:21:032022-11-23 18:21:05

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-23 18:21:05]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:6168kb
  • [2022-11-23 18:21:03]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << "[" << __LINE__ << ' ' << #x << "]: " << (x) << endl

int main() {
    cin.tie(0)->sync_with_stdio(0);

    int n;
    cin >> n;

    vector<tuple<int, int, string, int>> a, b;
    for (int i=0; i<n; i++) {
        string s;
        cin >> s;
        int cur = 0, mn = 0, mx = 0;
        for (char c : s) {
            if (c == '(') cur++;
            else cur--;
            mn = min(mn, cur);
            mx = max(mx, cur);
        }
        if (cur >= 0) a.emplace_back(mn, cur, s, i);
        else b.emplace_back(-mx, -cur, s, i);
    }

    sort(a.begin(), a.end(), [&](auto& x, auto& y) {
        if (get<0>(x) != get<0>(y)) return get<0>(x) > get<0>(y);
        return get<1>(x) > get<1>(y);
    });
    sort(b.begin(), b.end(), [&](auto& x, auto& y) {
        if (get<0>(x) != get<0>(y)) return get<0>(x) < get<0>(y);
        return get<1>(x) < get<1>(y);
    });

    vector<int> ans;
    int cur = 0;
    bool flag = true;
    for (auto& [x, _, y, z] : a) {
        for (char c : y) {
            if (c == '(') cur++;
            else cur--;
            if (cur < 0) flag = false;
        }
        ans.push_back(z);
    }
    for (auto& [x, _, y, z] : b) {
        for (char c : y) {
            if (c == '(') cur++;
            else cur--;
            if (cur < 0) flag = false;
        }
        ans.push_back(z);
    }

    if (cur != 0 || !flag) cout << "impossible\n";
    else {
        for (int e : ans) cout << e+1 << '\n';
    }

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 16ms
memory: 6168kb

input:

50000
(
(
))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()(
)
(
)
(((
(
(
(
(
(
()
(
)
(
)((())()((
)))))(
(
)
))
)()
(
)
)
)()(
(
(
()
(
)
(
)()((((())()))())(
(
(
)(
(
(
(()())())
)
)
(
(
(
)((())))((())))))))))((((()()))()))))))))((()())()))
)
)()
)
)
)
)
)
())(())))))()(()((()(())...

output:

impossible

result:

wrong answer you didn't find a solution but jury did