QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#368929 | #4212. Brackets | zhaohaikun | RE | 1ms | 9796kb | C++14 | 767b | 2024-03-27 18:15:17 | 2024-03-27 18:15:17 |
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()) {
st.erase(p), p = st.lower_bound(i);
assert(p != st.end());
st.erase(p), ans[i] = ans[nxt[i]] = 1;
}
}
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9796kb
input:
2 1 2 1 2
output:
()()
result:
ok single line: '()()'
Test #2:
score: 0
Accepted
time: 1ms
memory: 7712kb
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