제출 #930239

#제출 시각아이디문제언어결과실행 시간메모리
93023912345678괄호 문자열 (CEOI16_match)C++17
37 / 100
2015 ms1104 KiB
#include <bits/stdc++.h> using namespace std; const int nx=1e5+5; int n; string s; stack<int> st; int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>s; n=s.size(); for (auto x:s) { if (st.empty()||st.top()!=x) st.push(x); else st.pop(); } if (!st.empty()) return cout<<-1, 0; while (!st.empty()) st.pop(); for (int i=0; i<n; i++) { if (st.empty()||st.top()!=s[i]) cout<<'(', st.push(s[i]); else { stack<int> tmp=st; tmp.push(s[i]); for (int j=i+1; j<n; j++) { if (tmp.empty()||tmp.top()!=s[j]) tmp.push(s[j]); else tmp.pop(); } if (tmp.empty()) cout<<'(', st.push(s[i]); else cout<<')', st.pop(); } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...