Submission #127212

#TimeUsernameProblemLanguageResultExecution timeMemory
127212PlurmMatch (CEOI16_match)C++11
10 / 100
2 ms504 KiB
#include <bits/stdc++.h> using namespace std; char str[100005]; char ans[100005]; int prefh[100005]; bool recur(int l, int r){ if(r < l) return true; if((r - l) % 2 == 0) return false; int mx = -1; for(int i = l+1; i <= r; i++){ if((prefh[i] ^ prefh[l-1]) == 0 && str[i] == str[l]){ mx = i; } } if(mx == -1) return false; ans[l] = '('; ans[mx] = ')'; return recur(l+1, mx-1) && recur(mx+1, r); } int main(){ scanf("%s",str+1); int n = strlen(str+1); for(int i = 1; i <= n; i++){ prefh[i] = prefh[i-1] ^ (1 << (str[i] - 'a')); } if(recur(1, n)){ ans[n+1] = '\0'; printf("%s",ans+1); }else{ printf("-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",str+1);
     ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...