#include <iostream>
#include <stack>
#include <algorithm>
#include <string>
using namespace std;
int n;
string s;
stack <int> S;
void task() {
int sum = 0;
string w = "";
for (int i = 0; i < n; i++) {
if (S.empty()) {
sum++;
w.insert(w.size(), "(");
S.push(s[i]);
}
else {
int v = S.top();
if (v == s[i]) {
sum--;
S.pop();
w.insert(w.size(), ")");
}
else {
sum++;
w.insert(w.size(), "(");
S.push(s[i]);
}
}
}
if (sum != 0) cout << -1;
else cout << w;
return;
}
int main()
{
cin >> s;
n = s.size();
task();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |