Submission #52882

# Submission time Handle Problem Language Result Execution time Memory
52882 2018-06-27T06:13:42 Z 노영훈(#1382) Match (CEOI16_match) C++11
10 / 100
1678 ms 3020 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=500010, inf=2e9;

int n;

char S[MX], R[MX];

bool solve(int s){
    for(int i=0; i<n; i++)
        R[i+1] = (s&(1<<(n-i-1)))!=0 ? ')' : '(';
    int sum=0;
    for(int i=1; i<=n; i++) sum+=(R[i]=='(' ? 1 : -1);
    if(sum!=0) return false;
    int mat[MX]={};
    bool done[MX]={};
    for(int i=1; i<=n; i++){
        if(done[i]) continue;
        for(int j=i, cnt=0; j<=n; j++){
            cnt+= ( R[j]=='(' ? 1 : -1 );
            if(cnt<0) return false;
            if(cnt==0){
                mat[i]=j;
                done[i]=done[j]=true;
                break;
            }
        }
        if(S[i]!=S[mat[i]]) return false;
    }
    return true;
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>(S+1);
    for(int i=1; S[i]!=0; i++) n=i;
    if(n>20){
        cout<<-1;
        return 0;
    }
    for(int i=0; i<(1<<n); i++){
        if(solve(i)){
            cout<<(R+1);
            return 0;
        }
    }
    cout<<-1;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2812 KB Output is correct
2 Correct 4 ms 2812 KB Output is correct
3 Correct 1678 ms 3020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2812 KB Output is correct
2 Correct 4 ms 2812 KB Output is correct
3 Correct 1678 ms 3020 KB Output is correct
4 Incorrect 2 ms 3020 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2812 KB Output is correct
2 Correct 4 ms 2812 KB Output is correct
3 Correct 1678 ms 3020 KB Output is correct
4 Incorrect 2 ms 3020 KB Output isn't correct
5 Halted 0 ms 0 KB -