QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#571784 | #4212. Brackets | zhaohaikun | RE | 1ms | 9892kb | C++23 | 834b | 2024-09-18 08:37:07 | 2024-09-18 08:37:07 |
Judging History
answer
// test
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
using namespace std;
const int N = 1e6;
int n, p[N], nxt[N], h[N], ans[N], pre[N];
set < int > st;
int main() {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
L(i, 1, n * 2)
cin >> p[i], nxt[h[p[i]]] = i, h[p[i]] = i;
L(i, 1, n)
st.insert(i * 2 - 1);
L(i, 1, n * 2)
if(nxt[i]) {
auto p = st.lower_bound(nxt[i]);
if(p != st.end()) {
// int w = *p;
st.erase(p), p = st.lower_bound(i);
// if(p != st.end()) return puts("("), 0;
st.erase(p), ans[i] = ans[nxt[i]] = 1;
// else st.insert(w);
}
}
L(i, 1, n * 2) {
pre[i] = pre[i - 1] + ans[i] - (!ans[i]);
if(pre[i] < 0) return cout << "(\n", 0;
}
L(i, 1, n * 2) cout << (ans[i] ? '(' : ')');
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9892kb
input:
2 1 2 1 2
output:
()()
result:
ok single line: '()()'
Test #2:
score: 0
Accepted
time: 1ms
memory: 7796kb
input:
1 1 1
output:
(
result:
ok single line: '('
Test #3:
score: -100
Runtime Error
input:
4 4 3 1 2 3 2 1 4