QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#613240 | #4212. Brackets | yaoyanfeng | RE | 0ms | 0kb | C++14 | 879b | 2024-10-05 13:48:06 | 2024-10-05 13:49:08 |
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1000100;
int n;
int a[N << 1], r[N];
int ret[N << 1];
int main() {
freopen("brackets.in", "r", stdin);
freopen("brackets.out", "w", stdout);
scanf("%d", &n);
for (int i = 1; i <= n * 2; ++i) scanf("%d", a + i), r[a[i]] = i;
if (n % 2 != 0) {
puts(":(");
return 0;
}
for (int i = 1, ans = n; i <= n * 2; ++i) {
if (ret[i]) continue;
int t = r[a[i]];
if (ans > 0 && t != n * 2) ret[i] = ret[t] = 1, ans -= 2;
else ret[i] = ret[t] = 2;
}
int o = 0;
for (int i = 1; i <= n * 2; ++i) {
if (ret[i] == 1) ++o;
else --o;
if (o < 0) {
puts(":(");
return 0;
}
}
for (int i = 1; i <= n * 2; ++i) putchar(ret[i] == 1 ? '(' : ')');
return 0;
}
详细
Test #1:
score: 0
Dangerous Syscalls
input:
2 1 2 1 2