#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#define int int64_t
using namespace std;
struct brackseq
{
string s;
int n;
string calc()
{
vector<int> stack;
string seq;
vector<vector<vector<int>>> chlist(n, vector<vector<int>>(255));
for (int i = 0; i < n; i++)
{
if (stack.size() == 0 || s[i] != s[stack.back()])
{
chlist[stack.size()][s[i]].push_back(i);
stack.push_back(i);
seq.push_back('(');
}
else
{
stack.pop_back();
seq.push_back(')');
chlist[stack.size()][s[i]].push_back(i);
}
}
if (stack.size() != 0) return "-1";
for (int i = 0; i < n; i++)
{
for (int j = 0; j < 255; j++)
{
int ls = chlist[i][j].size();
for (int k = 0; k < ls/2; k++)
{
seq[chlist[i][j][k]] = '(';
seq[chlist[i][j][ls - k - 1]] = ')';
}
}
}
return seq;
}
};
signed main()
{
brackseq bs;
cin >> bs.s;
bs.n = bs.s.size();
cout << bs.calc() << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |