QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#625366#4212. BracketshhoppitreeRE 0ms0kbC++17822b2024-10-09 18:54:182024-10-09 18:54:19

Judging History

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

  • [2024-10-09 18:54:19]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-09 18:54:18]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;

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

signed main() {
    freopen("fate.in", "r", stdin);
    freopen("fate.out", "w", stdout);
    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("(");
            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: 0
Dangerous Syscalls

input:

2
1 2 1 2

output:


result: