QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#571787 | #4212. Brackets | zhaohaikun | WA | 0ms | 7764kb | C++23 | 873b | 2024-09-18 08:40:37 | 2024-09-18 08:40:38 |
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];
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);
}
}
if (st.size()) return puts("("), 0;
// 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: 0
Wrong Answer
time: 0ms
memory: 7764kb
input:
2 1 2 1 2
output:
(
result:
wrong answer 1st lines differ - expected: '()()', found: '('