QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#625370 | #4212. Brackets | hhoppitree | TL | 1ms | 5784kb | C++17 | 746b | 2024-10-09 18:54:36 | 2024-10-09 18:54:37 |
Judging History
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