Submission #42442

#TimeUsernameProblemLanguageResultExecution timeMemory
42442nonocutMatch (CEOI16_match)C++14
10 / 100
2033 ms3312 KiB
#include<bits/stdc++.h> using namespace std; const int maxn = 2e3 + 5; int n; char s[maxn], a[maxn], ans[maxn]; int val[maxn]; set<int> pos[30][maxn]; void solve(int l, int r) { // printf("solve %d %d\n",l,r); if(l>r) return ; int x = *(--pos[s[l]-'a'][val[l-1]].upper_bound(r)); ans[l] = '('; ans[x] = ')'; solve(l+1,x-1); solve(x+1,r); } int main() { scanf(" %s",s); n = strlen(s); int r = 0; for(int i=0;i<n;i++) { a[++r] = s[i]; while(r>=2 && a[r]==a[r-1]) r-=2; val[i] = r; pos[s[i]-'a'][val[i]].insert(i); } if(r>0) return !printf("-1"); solve(0,n-1); printf("%s",ans); }

Compilation message (stderr)

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