This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |