QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#625370#4212. BracketshhoppitreeTL 1ms5784kbC++17746b2024-10-09 18:54:362024-10-09 18:54:37

Judging History

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

  • [2024-10-09 18:54:37]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:5784kb
  • [2024-10-09 18:54:36]
  • 提交

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("(");
            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;
}

详细

Test #1:

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

input:

2
1 2 1 2

output:

()()

result:

ok single line: '()()'

Test #2:

score: 0
Accepted
time: 1ms
memory: 5780kb

input:

1
1 1

output:

(

result:

ok single line: '('

Test #3:

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

input:

4
4 3 1 2 3 2 1 4

output:

(

result:

ok single line: '('

Test #4:

score: 0
Accepted
time: 1ms
memory: 5684kb

input:

4
3 1 2 1 4 3 2 4

output:

(()()())

result:

ok single line: '(()()())'

Test #5:

score: 0
Accepted
time: 1ms
memory: 5776kb

input:

4
2 4 3 1 3 4 2 1

output:

()()()()

result:

ok single line: '()()()()'

Test #6:

score: 0
Accepted
time: 1ms
memory: 5784kb

input:

4
4 4 3 3 1 2 1 2

output:

(((())))

result:

ok single line: '(((())))'

Test #7:

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

input:

4
1 3 1 2 4 4 2 3

output:

()(())()

result:

ok single line: '()(())()'

Test #8:

score: -100
Time Limit Exceeded

input:

11
3 9 10 5 4 7 7 8 11 9 5 3 6 1 2 11 10 6 1 2 4 8

output:


result: