QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#625360#4212. BracketshhoppitreeWA 1ms5772kbC++17747b2024-10-09 18:53:092024-10-09 18:53:09

Judging History

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

  • [2024-10-09 18:53:09]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5772kb
  • [2024-10-09 18:53:09]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;

int nxt[N << 1], lst[N];

signed main() {
    int n; scanf("%d", &n);
    for (int i = 1, x; i <= n * 2; ++i) {
        scanf("%d", &x);
        if (lst[x]) nxt[lst[x]] = i;
        else lst[x] = i;
    }
    string res(n * 2 + 1, ')');
    set<int> S;
    for (int i = 1; i < 2 * n; i += 2) S.insert(i);
    for (int i = 1; !S.empty(); ++i) {
        if (*S.begin() < i) {
            puts("-1");
            exit(0);
        }
        if (nxt[i] && *S.rbegin() >= nxt[i]) {
            S.erase(*S.begin()), S.erase(S.lower_bound(nxt[i]));
            res[i] = res[nxt[i]] = '(';
        }
    }
    puts(res.substr(1).c_str());
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5772kb

input:

2
1 2 1 2

output:

()()

result:

ok single line: '()()'

Test #2:

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

input:

1
1 1

output:

-1

result:

wrong answer 1st lines differ - expected: '(', found: '-1'