Submission #42438

#TimeUsernameProblemLanguageResultExecution timeMemory
42438nonocutMatch (CEOI16_match)C++14
0 / 100
6 ms6112 KiB
#include<bits/stdc++.h> using namespace std; const int maxn = 2e3 + 5; int n; char s[maxn], a[maxn], ans[maxn]; set<int> pos[30][maxn]; void solve(int l, int r, int cur) { if(l>r) return ; int x = *(--pos[s[l]-'a'][cur].upper_bound(r)); ans[l] = '('; ans[x] = ')'; solve(l+1,x-1,cur+1); solve(x+1,r,cur); } 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; pos[s[i]-'a'][r].insert(i); } if(r>0) return !printf("-1"); solve(0,n-1,0); printf("%s",ans); }

Compilation message (stderr)

match.cpp: In function 'int main()':
match.cpp:14: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...