# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
116523 | 2019-06-12T16:50:37 Z | IOrtroiii | Match (CEOI16_match) | C++14 | 23 ms | 20096 KB |
#include <bits/stdc++.h> using namespace std; const int N = 100100; char s[N]; int let[N]; int par[N]; int nxt[N][26]; int last[N][26]; int opt[N][26]; int tot; void solve(int l, int r) { if (l > r) return; int opt = ::opt[r][s[l] - 'a']; if (opt <= l) { puts("-1"); exit(0); } s[l] = '(', s[opt] = ')'; solve(l + 1, opt - 1); solve(opt + 1, r); } int main() { scanf("%s", s + 1); int n = strlen(s + 1); int cur = 0; for (int i = 1; i <= n; ++i) { if (let[cur] == s[i]) { cur = par[cur]; } else { int &nxt = ::nxt[cur][s[i] - 'a']; if (!nxt) { nxt = ++tot; par[nxt] = cur; let[nxt] = s[i]; } cur = nxt; } last[cur][s[i] - 'a'] = i; for (int j = 0; j < 26; ++j) { opt[i][j] = last[cur][j]; } } solve(1, n); puts(s + 1); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 512 KB | Output is correct |
5 | Correct | 2 ms | 640 KB | Output is correct |
6 | Correct | 2 ms | 512 KB | Output is correct |
7 | Correct | 2 ms | 640 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 512 KB | Output is correct |
5 | Correct | 2 ms | 640 KB | Output is correct |
6 | Correct | 2 ms | 512 KB | Output is correct |
7 | Correct | 2 ms | 640 KB | Output is correct |
8 | Correct | 3 ms | 1536 KB | Output is correct |
9 | Correct | 3 ms | 1664 KB | Output is correct |
10 | Correct | 5 ms | 1792 KB | Output is correct |
11 | Correct | 3 ms | 1792 KB | Output is correct |
12 | Correct | 14 ms | 13184 KB | Output is correct |
13 | Correct | 17 ms | 14336 KB | Output is correct |
14 | Correct | 17 ms | 15232 KB | Output is correct |
15 | Correct | 11 ms | 9856 KB | Output is correct |
16 | Correct | 11 ms | 9728 KB | Output is correct |
17 | Correct | 17 ms | 14712 KB | Output is correct |
18 | Correct | 14 ms | 10368 KB | Output is correct |
19 | Correct | 22 ms | 19576 KB | Output is correct |
20 | Correct | 16 ms | 13312 KB | Output is correct |
21 | Correct | 23 ms | 20096 KB | Output is correct |