QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#626021 | #4212. Brackets | hhoppitree | WA | 1ms | 5728kb | C++17 | 784b | 2024-10-09 22:25:15 | 2024-10-09 22:25:16 |
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);
if (n & 1) return 0 & puts(")");
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: 5728kb
input:
2 1 2 1 2
output:
()()
result:
ok single line: '()()'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3568kb
input:
1 1 1
output:
)
result:
wrong answer 1st lines differ - expected: '(', found: ')'