Submission #467369

#TimeUsernameProblemLanguageResultExecution timeMemory
467369fuad27Match (CEOI16_match)C++17
100 / 100
19 ms12332 KiB
#include <bits/stdc++.h> using namespace std; char s[100010],ans[100010]; int op[100010][26]; void solve(int l, int r) { if(l > r) return; if(op[r][s[l]-'a'] <= l) { cout<<-1<<endl;; exit(0); } ans[l] = '(', ans[op[r][s[l]-'a']] = ')'; solve(l+1, op[r][s[l]-'a']-1), solve(op[r][s[l]-'a']+1, r); } int main() { scanf("%s", s); int n = strlen(s); for(int i=0; i<n; i++) { for(int j=0; j<26; j++) if(j == s[i]-'a') op[i][j] = i; else if(i && op[i-1][s[i]-'a'] > 0) op[i][j] = op[op[i-1][s[i]-'a']-1][j]; else op[i][j] = -1; } solve(0,n-1); cout<<ans; return 0; }

Compilation message (stderr)

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