QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#613272#4212. BracketsyaoyanfengWA 1ms7916kbC++14793b2024-10-05 13:50:592024-10-05 13:51:02

Judging History

你现在查看的是最新测评结果

  • [2024-10-05 13:51:02]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7916kb
  • [2024-10-05 13:50:59]
  • 提交

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: '('