QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#625360 | #4212. Brackets | hhoppitree | WA | 1ms | 5772kb | C++17 | 747b | 2024-10-09 18:53:09 | 2024-10-09 18:53:09 |
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("-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'