이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// 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 time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |