# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90486 | 2018-12-21T20:53:30 Z | tincamatei | Match (CEOI16_match) | C++14 | 2 ms | 628 KB |
#include <bits/stdc++.h> using namespace std; int st[100000], top; int nextPoz[26][100001]; vector<int> poz[26]; bool solve(int l, int r, string &str, string &par, int dep = 0) { int nr = 0, cnt = 0; bool lastP = false; bool rez = true; if(l == r + 1) return true; if(r == str.size()) return false; for(int i = l; i <= r; i = nextPoz[str[i] - 'a'][i]) { ++nr; if(nextPoz[str[i] - 'a'][i] <= r) rez &= solve(i + 1, nextPoz[str[i] - 'a'][i] - 1, str, par, dep + 1); if(i == r) lastP = true; } rez &= lastP; if(nr % 2 == 1) return false; for(int i = l; i <= r; i = nextPoz[str[i] - 'a'][i]) if(cnt++ < nr / 2) par[i] = '('; else par[i] = ')'; return true & rez; } int main() { string str, par; cin >> str; for(int i = 0; i < str.size(); ++i) poz[str[i] - 'a'].push_back(i); par.resize(str.size()); for(int j = 0; j < 26; ++j) { int lastP = str.size(); for(int i = str.size() - 1; i >= 0; --i) { nextPoz[j][i] = lastP; if(str[i] == j + 'a') lastP = i; } } if(solve(0, str.size() - 1, str, par)) cout << par; else cout << -1; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Incorrect | 2 ms | 628 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Incorrect | 2 ms | 628 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Incorrect | 2 ms | 628 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |