QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#613240#4212. BracketsyaoyanfengRE 0ms0kbC++14879b2024-10-05 13:48:062024-10-05 13:49:08

Judging History

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

  • [2024-10-05 13:49:08]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-05 13:48:06]
  • 提交

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

2
1 2 1 2

output:


result: