Submission #132227

#TimeUsernameProblemLanguageResultExecution timeMemory
132227johuthaMatch (CEOI16_match)C++14
0 / 100
2 ms504 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...