답안 #475685

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
475685 2021-09-23T16:22:24 Z Blobo2_Blobo2 괄호 문자열 (CEOI16_match) C++14
0 / 100
0 ms 204 KB
/*
Editor: Abdelrahman Hossam
Nickname: Blobo2_Blobo2
IOI next year isA :)
*/
/*#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")*/

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define gen(arr,n,nxt)  generate(arr,arr+n,nxt)
#define Blobo2_el_7akim_elly_3ayz_yro7_IOI_w_3ayz_yakol_jilaty ios_base::sync_with_stdio(false);cin.tie(0);
#define EPS 0.00000001

const int mo=1e9+7,INF=1e18;
int nxt(){int x;cin>>x;return x;}
string s,ans;
vector<int>v[26];
void solve(int l=0,int r = s.size()-1){
    //cout<<l<<' '<<r<<' '<<ans<<' ';
    if(l>r)
        return;
    if(s[l] == s[r] && r%2!=l%2 && ans[l]!='(' && ans[l]!=')'){
        //cout<<"ok1"<<endl;
        bool ok=0;
        for(int i=0;i<26;i++){
            if(v[i].empty())continue;
            int szl = upper_bound(all(v[i]),l) - v[i].begin();
            int s=0,e=v[i].size()-1;
            while(s<=e){
                int mid=(s+e)>>1;
                if(v[i][mid]>=r)e=mid-1;
                else s=mid+1;
            }
            int szr = e;
            if((szr-szl+1)%2 == 1){
                ok=1;
                goto a;
            }
        }
        ans[l]='(';
        ans[r]=')';
        solve(l+1,r-1);
        solve(r+1,s.size()-1);
    }
    else{
        //cout<<"ok2"<<endl;
        a:;
        solve(l,r-1);
    }
}
signed main(){
    Blobo2_el_7akim_elly_3ayz_yro7_IOI_w_3ayz_yakol_jilaty
    cin>>s;
    int n=s.size();
    for(int i=0;i<n;i++)
        v[s[i]-'a'].push_back(i),ans+='*';
    stack<int>st;
    for(int i=0;i<n;i++){
        if(!st.empty() && st.top() == s[i])st.pop();
        else st.push(s[i]);
    }
    if(st.size()){
        cout<<-1<<endl;
        return 0;
    }
    solve();
    cout<<ans<<endl;
    return 0;
}

Compilation message

match.cpp: In function 'void solve(long long int, long long int)':
match.cpp:31:14: warning: variable 'ok' set but not used [-Wunused-but-set-variable]
   31 |         bool ok=0;
      |              ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -