이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define GOOD_LUCK ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define itn int
#define INF 100000000
#define MOD 998244353
#define MAX 103
#define endl "\n"
#define ff first
#define ss second
using namespace std;
int temp;
signed main() {
GOOD_LUCK
int t;
t = 1;
// cin >> t;
while (t--) {
int n;
string a;
cin >> a;
n = a.size();
if (n % 2 != 0) {
cout << -1;
return 0;
}
stack <char> s;
map <char, int> m;
for (int i=0; i < n; i++) {
m[a[i]]++;
if (s.empty()) s.push(a[i]);
else if (s.top() == a[i]) s.pop();
else s.push(a[i]);
}
/*for (auto i : m) {
cout << i.ff << ' ' << i.ss;
cout << endl;
}*/
if (s.empty()) {
for (auto i : m) {
if (i.ss % 2 != 0) {
cout << -1;
return 0;
}
}
string ans = "";
for (int i=0; i < n; i++) {
if (m[a[i]] > 0) {
ans = ans + '(';
m[a[i]]-=2;
}
else {
ans += ')';
}
}
cout << ans;
}
else {
cout << -1;
}
}
return 0;
}
// Problem C
// by Ekber_Ekber
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |