답안 #1117662

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1117662 2024-11-24T07:15:52 Z vjudge1 괄호 문자열 (CEOI16_match) C++14
10 / 100
2000 ms 456 KB
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define pb push_back
#define F first
#define S second
#define ll long long
#define int ll
#define pii pair<int, int>
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define M_PI 3.14159265358979323846
#define all(v) v.begin(), v.end()
#define pss pair<string, string>
#define no cout<<"No"<<endl;
#define yes cout<<"Yes"<<endl;
#define imp cout<<-1<<endl;
#define flu cout.flush();
#define Endl endl

const int N = 100009;
const int mod = 1e9+7;

void solve(){
    string s;
    cin>>s;
    int n;
    n=s.size();
    vector<string>res;
    for(int i=0; i<(1<<n); i++){
        string a="";
        for(int j=0; j<n; j++){
            if(i&(1<<j)){
                a=a+"(";
            }
            else{
                a=a+")";
            }
        }
        int qwe=0, yx=0;
        for(int i=0; i<n; i++){
            if(a[i]==')'){
                qwe--;
            }
            else{
                qwe++;
            }
            if(qwe<0){
                yx++;
                break;
            }
        }
        if(yx!=0 or qwe!=0){
            continue;
        }
        vector<char>st;
        for(int i=0; i<n; i++){
            if(a[i]=='('){
                st.pb(s[i]);
            }
            else{
                char let=st[st.size()-1];
                if(s[i]==let){
                    st.pop_back();
                }
                else{
                    yx++;
                    break;
                }
            }
        }
        if(yx==0){
            res.pb(a);
        }
    }
    if(res.size()==0){
        imp;
        return;
    }
    sort(all(res));
    cout<<res[0]<<endl;
}

signed main(){
    io;
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 97 ms 336 KB Output is correct
3 Correct 20 ms 456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 97 ms 336 KB Output is correct
3 Correct 20 ms 456 KB Output is correct
4 Execution timed out 2037 ms 336 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 97 ms 336 KB Output is correct
3 Correct 20 ms 456 KB Output is correct
4 Execution timed out 2037 ms 336 KB Time limit exceeded
5 Halted 0 ms 0 KB -