제출 #826535

#제출 시각아이디문제언어결과실행 시간메모리
826535NK_Match (CEOI16_match)C++17
0 / 100
0 ms320 KiB
// Success consists of going from failure to failure without loss of enthusiasm #include <bits/stdc++.h> using namespace std; #define nl '\n' #define pb push_back #define mp make_pair #define f first #define s second #define sz(x) int(x.size()) template<class T> using V = vector<T>; using vi = V<int>; using ll = long long; using pl = pair<ll, ll>; using vl = V<ll>; int main() { cin.tie(0)->sync_with_stdio(0); string S; cin >> S; vi F(26); for(auto& x : S) F[x-'a']++; vi H = F; for(int c = 0; c < 26; c++) { if (F[c] & 1) { cout << -1 << nl; return 0; } H[c] /= 2; } vi stk; string ans; for(int i = 0; i < sz(S); i++) { int c = S[i] - 'a'; if (F[c] > H[c]) ans += "(", stk.pb(c); else { ans += ")"; if (stk.back() != c) { cout << -1 << nl; return 0; } stk.pop_back(); } F[c]--; } if (sz(stk)) cout << -1 << nl; else cout << ans << nl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...