Submission #30818

#TimeUsernameProblemLanguageResultExecution timeMemory
30818zscoder괄호 문자열 (CEOI16_match)C++14
37 / 100
2000 ms31392 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define fi first #define se second #define mp make_pair #define pb push_back #define fbo find_by_order #define ook order_of_key typedef long long ll; typedef pair<int,ll> ii; typedef vector<int> vi; typedef long double ld; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; typedef set<ll>::iterator sit; typedef map<ll,ll>::iterator mit; bool err; string s; void solve(int l, int r) { if(l>r) return ; stack<char> S; string ans; int idx=-1; if(s[l]==s[r]) { solve(l+1,r-1); if(err) return ; s[l]='('; s[r]=')'; return ; } for(int i = r; i > l; i--) { if(!S.empty()&&S.top()==s[i]) { S.pop(); } else { S.push(s[i]); } if(s[l]==s[i-1]&&S.empty()) { idx=i; break; } } if(idx<=l) { err=true; return ; } solve(l+1,idx-2); solve(idx,r); s[l]='('; s[idx-1]=')'; } char a[100011]; int main() { scanf("%s", a); int idx=0; while(a[idx]!='\0') { s+=a[idx]; idx++; } solve(0,int(s.length())-1); if(err) cout<<-1<<'\n'; else cout<<s<<'\n'; }

Compilation message (stderr)

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