답안 #244682

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
244682 2020-07-04T15:00:47 Z evpipis 괄호 문자열 (CEOI16_match) C++11
0 / 100
5 ms 384 KB
#include <bits/stdc++.h>
using namespace std;

const int len = 1e5+5;
char str[len], out[len];
int pref[len];

int solve(int l, int r, int bit){
    if (l > r) return 1;

    int k = 0;
    for (int i = l+1; i <= r; i++)
        if (str[i] == str[l] && pref[i] == bit) k = i;

    if (!k) return 0;

    out[l] = '(';
    out[k] = ')';

    return solve(l+1, k-1, bit^(1<<(str[l]-'a')))|solve(k+1, r, bit);
}

int main(){
    scanf("%s", str);
    int n = strlen(str);

    for (int i = 0, bit = 0; i < n; i++){
        bit ^= (1<<(str[i]-'a'));
        pref[i] = bit;
    }

    int ans = solve(0, n-1, 0);
    if (!ans){
        printf("-1\n");
        return 0;
    }

    for (int i = 0; i < n; i++)
        printf("%c", out[i]);
    printf("\n");
    return 0;
}

Compilation message

match.cpp: In function 'int main()':
match.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", str);
     ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Incorrect 5 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Incorrect 5 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Incorrect 5 ms 384 KB Output isn't correct