Submission #1118032

#TimeUsernameProblemLanguageResultExecution timeMemory
1118032vjudge1Match (CEOI16_match)C++17
0 / 100
1 ms336 KiB
#pragma GCC optimize("O3") #include<bits/stdc++.h> #define ll long long #define endl "\n" #define AI ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; vector<ll>val; vector<vector<ll>>edge; vector<ll>check; ll k,c=0; int main() { AI //freopen(“kangaroo.in”, “r”, stdin); // freopen(“kangaroo.out”, “w”, stdout); ll i,j,k; string a; cin>>a; if(a.size()%2) { cout<<-1; return 0; }//1->( 0->) ll n=a.size(); for(i=(1<<(n/2))-1;i<(1<<n);i++) { ll bal=0; k=1; for(j=0;j<n;j++) { if(i&k) bal++; else bal--; if(bal<0) break; k=(k<<1); } if(bal!=0) continue; stack<ll>stm; stack<ll>sta; char x; bool bo=true; k=1; for(j=0;j<n;j++) { // cout<<k; if(i&k) x='('; else x=')'; k=(k<<1); if(!stm.size()) { stm.push(x); sta.push(a[j]); continue; } if(stm.top()=='(' and x==')' and sta.top()!=a[j]) { bo=false; break; } else if(stm.top()=='(' and x==')' and sta.top()==a[j]) { sta.pop(); stm.pop(); } else { sta.push(a[j]); stm.push(x); } } if(stm.size() or sta.size() or !bo) continue; else { k=1; for(j=0;j<n;j++) { if(i&k) cout<<'('; else cout<<')'; k=(k<<1); } return 0; } } cout<<-1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...