답안 #176041

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
176041 2020-01-07T18:04:56 Z rzbt 괄호 문자열 (CEOI16_match) C++14
0 / 100
2 ms 376 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define MAXN 100005
typedef long long ll;


using namespace std;

int n;
char ss[MAXN],res[MAXN];
int x[MAXN];
set<pair<int,int> > s[30];
int tx;
bool obrisan[MAXN];


int main()
{
    scanf("%s",ss);
    n=strlen(ss);
    for(int i=1;i<=n;i++){
        int t=ss[i-1]-'a';
        tx^=(1<<t);
        x[i]=tx;
        s[t].insert(mp(tx,-i));
    }
    for(int i=1;i<=n;i++){
        if(obrisan[i])continue;
        int t=ss[i-1]-'a';
        auto a=s[t].lower_bound(mp(x[i-1],-n-5));
        if(a==s[t].end() || a->F!=x[i-1]){
            printf("-1");
            return 0;
        }
        //printf("   %d %d\n",i,-(a->S));
        res[i-1]='(';
        res[-(a->S)-1]=')';
        obrisan[i]=true;
        obrisan[-(a->S)]=true;
        s[t].erase(a);
        s[t].erase(mp(x[i],i));


    }

    printf("%s",res);
    return 0;
}

Compilation message

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