제출 #1117662

#제출 시각아이디문제언어결과실행 시간메모리
1117662vjudge1Match (CEOI16_match)C++14
10 / 100
2037 ms456 KiB
#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(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...