QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#625366 | #4212. Brackets | hhoppitree | RE | 0ms | 0kb | C++17 | 822b | 2024-10-09 18:54:18 | 2024-10-09 18:54:19 |
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