답안 #127212

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
127212 2019-07-09T06:45:59 Z Plurm 괄호 문자열 (CEOI16_match) C++11
10 / 100
2 ms 504 KB
#include <bits/stdc++.h>
using namespace std;
char str[100005];
char ans[100005];
int prefh[100005];
bool recur(int l, int r){
    if(r < l) return true;
    if((r - l) % 2 == 0) return false;
    int mx = -1;
    for(int i = l+1; i <= r; i++){
        if((prefh[i] ^ prefh[l-1]) == 0 && str[i] == str[l]){
            mx = i;
        }
    }
    if(mx == -1) return false;
    ans[l] = '(';
    ans[mx] = ')';
    return recur(l+1, mx-1) && recur(mx+1, r);
}
int main(){
    scanf("%s",str+1);
    int n = strlen(str+1);
    for(int i = 1; i <= n; i++){
        prefh[i] = prefh[i-1] ^ (1 << (str[i] - 'a'));
    }
    if(recur(1, n)){
        ans[n+1] = '\0';
        printf("%s",ans+1);
    }else{
        printf("-1");
    }
    return 0;
}

Compilation message

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