// Author RufatM
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e9+7
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define pb push_back
#define pii pair<ll,int>
#define all(a) a.begin(),a.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
signed main(){
int t=1;
//cin >> t;
while(t--){
fastio;
string S;
cin >> S;
int N = S.length();
vector<char> B(N);
stack<pair<char,int>> st;
for(int i = 0; i < N; i++) {
char c = S[i];
if(!st.empty() && st.top().first == c) {
B[st.top().second] = '(';
B[i] = ')';
st.pop();
} else {
st.push({c, i});
}
}
if(!st.empty()) {
cout << "-1\n";
return 0;
}
int balance = 0;
for(int i = 0; i < N; i++) {
if(B[i] == '(') balance++;
else if(B[i] == ')') balance--;
else {
cout << "-1\n";
return 0;
}
if(balance < 0) {
cout << "-1\n";
return 0;
}
}
if(balance != 0) {
cout << "-1\n";
return 0;
}
for(int i = 0; i < N; i++) {
cout << B[i];
}
cout << '\n';
}
}
//Allahim insallah tle vermez
//Yasasin Yaxsi Kiwiler
//Yasasin Info Azerbaijan
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |