QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#613257#4212. BracketsyaoyanfengWA 1ms7904kbC++14795b2024-10-05 13:49:342024-10-05 13:50:01

Judging History

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

  • [2024-10-05 13:50:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7904kb
  • [2024-10-05 13:49:34]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7904kb

input:

2
1 2 1 2

output:

()()

result:

ok single line: '()()'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 7824kb

input:

1
1 1

output:

:(

result:

wrong answer 1st lines differ - expected: '(', found: ':('