# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
110860 | mosesmayer | Match (CEOI16_match) | C++17 | 2 ms | 512 KiB |
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 <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mxsz = 1e5 + 5;
int n;
char S[mxsz], ans[mxsz];
int lft[mxsz][26];
void prec(){
for (int i = 1, p; i <= n; i++){
p = S[i] - 'a';
for (int j = 0; j < 26; j++){
lft[i][j] = lft[i-1][j];
}
lft[i][p] = i;
}
//for (int i = 1; i <= n; i++) for (int j = 0; j < 26; j++) cout << lft[i][j] << " \n"[j==25];
}
inline void CANNOT(){
puts("-1"); exit(0);
}
void rec(int l, int r){
//cout << l << ' ' << r << '\n';
if (l > r) return;
int pos = lft[r][S[l] - 'a'];
if (pos <= l) CANNOT();
ans[l] = '('; ans[pos] = ')';
rec(l+1, pos - 1); rec(pos+1, r);
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |