QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#613272 | #4212. Brackets | yaoyanfeng | WA | 1ms | 7916kb | C++14 | 793b | 2024-10-05 13:50:59 | 2024-10-05 13:51:02 |
Judging History
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() {
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: 100
Accepted
time: 1ms
memory: 7708kb
input:
2 1 2 1 2
output:
()()
result:
ok single line: '()()'
Test #2:
score: 0
Accepted
time: 1ms
memory: 7916kb
input:
1 1 1
output:
(
result:
ok single line: '('
Test #3:
score: 0
Accepted
time: 0ms
memory: 7664kb
input:
4 4 3 1 2 3 2 1 4
output:
(
result:
ok single line: '('
Test #4:
score: 0
Accepted
time: 1ms
memory: 7848kb
input:
4 3 1 2 1 4 3 2 4
output:
(()()())
result:
ok single line: '(()()())'
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 7840kb
input:
4 2 4 3 1 3 4 2 1
output:
(
result:
wrong answer 1st lines differ - expected: '()()()()', found: '('