#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i = a; i <= b; ++i)
#define pb push_back
typedef pair<char,int>pci;
string s;
string solve(){
string ret;
int n = (int)s.size();
ret.resize(n+1);
vector<pci>stk;
FOR(i,0,n-1){
if(stk.empty()) stk.pb(pci(s[i],i));
else{
if(stk.back().first == s[i]){
ret[stk.back().second] = '(';
ret[i] = ')';
stk.pop_back();
}
else stk.pb(pci(s[i],i));
}
}
if(!stk.empty()){
cout << "-1\n";
exit(0);
}
return ret;
}
int main(){
cin >> s;
cout << solve() << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
2020 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
2020 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
2020 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |