Submission #128033

#TimeUsernameProblemLanguageResultExecution timeMemory
128033PeppaPigMatch (CEOI16_match)C++14
10 / 100
59 ms61432 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5+5; int n, dep[N]; char a[N], ans[N]; stack<int> S; vector<int> id[N][26]; void solve(int l, int r) { if(l > r) return; vector<int> &v = id[dep[l]][a[l] - 'a']; auto it = --lower_bound(v.begin(), v.end(), r + 1); ans[l] = '(', ans[*it] = ')'; solve(l + 1, *it - 1), solve(*it + 1, r); } int main() { scanf("%s", a + 1); n = strlen(a + 1); for(int i = 1; i <= n; i++) { if(S.empty() || a[S.top()] != a[i]) { dep[i] = S.size() + 1; S.emplace(i); } else { dep[i] = dep[S.top()]; S.pop(); } } for(int i = 1; i <= n; i++) id[dep[i]][a[i] - 'a'].emplace_back(i); if(S.size()) return !printf("-1\n"); else solve(1, n); printf("%s\n", ans + 1); return 0; }

Compilation message (stderr)

match.cpp: In function 'int main()':
match.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", a + 1);
     ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...